Invalid use of null

What

Registered User.
Local time
Yesterday, 22:44
Joined
Oct 28, 2009
Messages
14
I'm stuck on how to solve this problem. The onclick code below is to open the names form, and is located on the application form. I want to set the initial view of the names form to the record with the name ID currently being viewed. This code does that perfectly.

However, if someone clicks the create record button in the nav bar, and then realizes they actually wanted to go to the names form, they are given the error "invalid use of null". I tried to correct it with the "if app_nmid = null then" portion of the if statement, but it didnt work.

Any help would be greatly appreciated!

Code:
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

If Me.app_nmID = Null Then
    DoCmd.OpenForm frmNames, acNormal
Else
    Dim rs As Object
    Dim lngBookmark As Long

    'set a variable to the current record
    lngBookmark = Me.app_nmID
    'open the new form
    DoCmd.OpenForm "frmNames"
    
    'take it to the selected record
    Set rs = Forms!frmNames.RecordsetClone
    rs.FindFirst "nmID = " & lngBookmark
    Forms!frmNames.Bookmark = rs.Bookmark
    
    Set rs = Nothing


    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmNames"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Form.Refresh
End If


Exit_Command40_Click:
    Exit Sub

Err_Command40_Click:
    MsgBox Err.Description
    Resume Exit_Command40_Click
    
End Sub
 
Try

If IsNull(Me.app_nmID) Then
 
I changed the syntax to what you wrote and it didnt work initially, but after changing 'DoCmd.OpenForm frmNames, acNormal' to 'DoCmd.OpenForms "frmNames"' it worked perfectly.

Thanks for your help!
 
Ah, I didn't notice that. Personally I would have all the declarations first, and since you set a variable to the form name later, I'd just use the variable in all instances of opening the form. Just noticed that these lines near the end aren't necessary; the form is already open:

Code:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmNames"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Form.Refresh

Glad you got it sorted out, and welcome to the site by the way!
 

Users who are viewing this thread

Back
Top Bottom