PDA

View Full Version : Solved: Yet another dLookup question



CreganTur
04-03-2008, 08:17 AM
I've got a form that contains unbound text boxes. When a User puts an account number into [text4] and click the seach button, I want dLookup to see if the value exists (true = OpenQuery that populates other unbound textboxes with data from table. false = message box)

Problem is that I keep getting errors- currently I'm getting a '424' error

Code:
Private Sub Command6_Click()
Dim sql1
Dim varX As Variant
'use dLookup to see if record exists before SQL runs
varX = DLookup("[AcctNmbr]", "tblAssignments", "[AcctNmbr] = 'me![Text4]'") '<<<Note1
'If Null then MsgBox for error and Exit Sub
If varX Is Null Then '<<<this is what's triggering the 424 error
MsgBox "Item does not exist"
Exit Sub
Else
'run query
End If
End Sub



Note 1 - I'm not sure if this dLookup is correct, because I'm testing it with an account# that does exist in the table, but it seems to be detecting it as Null (even though it should be a true result b/c the # does exist)

CreganTur
04-03-2008, 01:10 PM
Found the issue. It's because I was incorrectly checking to see if varX was null.

Changed: If varX Is Null Then

To:If IsNull(varX) Then

Trevor
04-05-2008, 11:09 AM
cragentur , I've done that one to :-)