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!
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