Need error help

P

pokdbz

I am getting an error right after: DoCmd.GoToRecord , , acNewRec
It is saying invalid use of null. Any ideas?


Private Sub Save_Click()
On Error GoTo Err_Save_Click

Dim checkSet1 As String

If Len(Me.SSN) = 9 Then
If MsgBox("Is this your correct Social Security Number " & SSN,
vbYesNo) = vbYes Then

DoCmd.GoToRecord , , acNewRec

'//////used to check Sets in the provider
table//////////////////////
checkSet1 = DLookup("SetB", "Provider", "SSN = '" & Me.SSN & "'")

'////////////////////////////////////////////////////////////////////

If checkSet1 = 1 Then
DoCmd.OpenForm ("PHQ")
End If
Else
MsgBox ("Please correct your Social Security number")
End If
Else
MsgBox ("Please enter your full Social Security number")

End If

Exit_Save_Click:
Exit Sub

Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click

End Sub
 
R

RoyVidar

pokdbz wrote in message
I am getting an error right after: DoCmd.GoToRecord , , acNewRec
It is saying invalid use of null. Any ideas?


Private Sub Save_Click()
On Error GoTo Err_Save_Click

Dim checkSet1 As String

If Len(Me.SSN) = 9 Then
If MsgBox("Is this your correct Social Security Number " & SSN,
vbYesNo) = vbYes Then

DoCmd.GoToRecord , , acNewRec

'//////used to check Sets in the provider
table//////////////////////
checkSet1 = DLookup("SetB", "Provider", "SSN = '" & Me.SSN & "'")

'////////////////////////////////////////////////////////////////////

If checkSet1 = 1 Then
DoCmd.OpenForm ("PHQ")
End If
Else
MsgBox ("Please correct your Social Security number")
End If
Else
MsgBox ("Please enter your full Social Security number")

End If

Exit_Save_Click:
Exit Sub

Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click

End Sub

You have declared checkSet1, which receives the result from the
Domain Aggregate, as a string. What probably happens here, is that
the Domain Aggregate doesn't find the passed SSN, and so returns
a Null, which will create the message you're getting, cause strings
cannot be set to Null.

One thing to try, is declaring checkSet1 as variant, then use the
IsNull function on it after assigning through the Domain Aggregate
to determine how to proceed.
 
P

pokdbz

I delcared checkSet1 as Variant and that didn't work. Was there something
else that I have to do?
The error that comes up when I do this is
You can't use the GoToRecord action or method on an object in Design View.

I don't have it open in Design view.
 
R

RoyVidar

It also seems you are trying to goto a new record before you have
validated this entry. Perhaps alter the sequence, so that the
gotorecord only occurs after verifying a valid ssn?

But the design message can also mean that some of the
methods of the docmd object aren't available when debugging,
but only when running the code without breakpoints.


pokdbz wrote in message
 
P

pokdbz

Yep moving it after the DLookup worked. Would have never thought of that.
Thanks for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top