Null Values in Forms

chrisguk

Registered User.
Local time
Today, 05:19
Joined
Mar 9, 2011
Messages
148
I have a cmd button executing the following code:

Code:
Private Sub btnNewItems_Click()
On Error GoTo Err_btnNewItems_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmNewOptions"
    
    stLinkCriteria = "[SitesID]=" & Me![sitesid]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "frmSitesMain", acSaveNo

Exit_btnNewItems_Click:
    Exit Sub

Err_btnNewItems_Click:
    MsgBox err.Description
    Resume Exit_btnNewItems_Click
    
End Sub

I have been thinking that I need an IF statement in there to state something like this:

Code:
Private Sub btnNewItems_Click()
On Error GoTo Err_btnNewItems_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmNewOptions"

IF Me."[SitesID]" = Null then

DoCmd.OpenForm stDocName, , , stLinkCriteria

Else

    stLinkCriteria = "[SitesID]=" & Me![sitesid]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "frmSitesMain", acSaveNo

End If
Exit_btnNewItems_Click:
    Exit Sub

Err_btnNewItems_Click:
    MsgBox err.Description
    Resume Exit_btnNewItems_Click
    
End Sub

Hold on have I just answered my own question. Can someone check the code for me?
 
Null is unknown. You can NOT do this

IF Me."[SitesID]" = Null then
also the quotes are incorrect.

You would use the

If IsNull(Me.sitesId) then...
 

Users who are viewing this thread

Back
Top Bottom