Help Needed: Open form at New Record if Null

chibicere

New member
Local time
Yesterday, 23:03
Joined
Jul 30, 2010
Messages
4
Hello All,

I am very new to SQL and I am sure this is a silly question. I want to open a form at a specific record based upon ID, but if ID field is Null I want to open a new record. I have the opening at a specific ID down, but can't seem to get my If IsNull statement right to create a new record if the ID is null.

Here's what I've got right now, this part is working and I've blocked out the part I tried to add in that I can't get to work successfully because I don't know the right syntax. You can see the form I am trying to open is called "Contact Details". Basically I don't know what to put after the Else statement to get it to move onto the next section of code.

Private Sub txtOpenContactsfrmExtended_Click()
Dim strWhere As String
Dim rs As DAO.Recordset

strWhere = "[ID]=" & Me.[ID]
DoCmd.OpenForm "Contact Details"

'If IsNull(Me.[ID]) Then DoCmd.GoToRecord , "", acNewRec Else

With Forms![Contact Details]
Set rs = .RecordsetClone
rs.FindFirst strWhere
If rs.NoMatch Then
MsgBox "Not found"
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing

End Sub

Thanks for any help you can give!
 
Here you go:
Code:
Private Sub txtOpenContactsfrmExtended_Click()

    If Len(Me.[ID] & "") = 0 Then
        DoCmd.OpenForm "Contact Details", , , , acFormAdd
    Else
        DoCmd.OpenForm "Contact Details", , , "[ID]=" & Me.[ID]
    End If
    
End Sub
Welcome to the forum!
 
Thanks for your help. I need the new form to be navigable when opened, not just filtered to the single record, which is why I was using such a complicated code for opening it to the correct record. Hence the acAddRecord code doesn't work because it tries to filter the form to only showing that single new record, and trying to show any other records without first closing and reopening the form will show "Record not Found." Any suggestions?
 

Users who are viewing this thread

Back
Top Bottom