Minggu, 09 April 2017

Re: [MS_AccessPros] Invalid use of Null

 

Khalid-


You can test for empty entries like this (right after the On Error statement):

    If (Len(Me.cmbDestination & "") = 0) Or (Len(Me.ProductID & "") = 0 Then
        ' Take alternative action - don't try to lookup the rate

    Else
        varRate = DLookup( ….
        Me.Rate = NZ(varRate, 0)
    End If


John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Apr 9, 2017, at 7:02 PM, khalidtanweerburrah@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:









------------------------------

Hi John,


I have a Form "New Cargo Collection Input" on its sub form "NewCargoCollectionInputsubform".

This sub form has a Text box "Rate" -->Standard, Decimal Places--> 2 on its On Got Focus event i 

have this code:


Private Sub Rate_GotFocus()

On Error Resume Next

    

    Dim varRate As Double

    varRate = DLookup("DestinationRate", "tblDestinationRates", _

              "Destination = '" & Me.cmbDestination & _

              "' AND ProductID = " & Me.ProductID & "")

              Me.Rate = Nz(varRate, 0)

End Sub


The issue is that if i omit the line "On Error Resume Next" i get an error message

Run-time error '94' Invalid use of Null


This happens when in "tblDestinationRates" there is no entry for Destination and ProductID

which is selected in sub form.


There is a form "Add New Destination Freight Rates" in which "DestinationRate" are entered for a 

specific Destination and ProductID when needed.


I need to know that is putting the line "On Error Resume Next" correct approach and logic ?

In this case, if there is no entry for Destination and ProductID. Text Box "Rate" shows 0.00 value 

and user enters value of his choice, else it picks the value from tblDestinationRates


Regards,

Khalid







__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar