Minggu, 09 April 2017

RE: [MS_AccessPros] Invalid use of Null

 

Hello Khalid

When there is no matching record, DLookup returns Null.  You are assigning the returned value to varRate, which is declared as a Double.  You cannot assign Null to a Double, hence the error.

Simply change the declaration:
    Dim varRate As Variant

Best wishes,
Graham

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Monday, 10 April 2017 05:02
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Invalid use of Null

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

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: "Graham Mandeno" <graham@mandeno.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (6)

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