Originally Posted by
sbar1
I am currently using the code below, but want to modify it so if one of the three fields below is NULL that it will pull records matching the other two. Any help would be appreciated, I could not figure it out playing around with anything I found online.
stLinkCriteria = "([BU]= '" & Me![buselect] & _
"') And ([Quarter]='" & Me![quarterselect] & _
"') And ([Yr]='" & Me![yrselect] & "')"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Build the WHERE clause on-the-fly(something like this):
Code:
Dim stLinkCriteria As String
stLinkCriteria = ""
If Not IsNull(Me.buselect) Then
stLinkCriteria = "[BU]= '" & Me.buselect & "' AND "
End If
If Not IsNull(Me.quarterselect) Then
stLinkCriteria = stLinkCriteria & "[Quarter]='" & Me.quarterselect & "' AND "
End If
If Not IsNull(Me.yrselect) Then
stLinkCriteria = stLinkCriteria & "[Yr]= '" & Me.yrselect & "' AND "
End If
If Len(Trim(stLinkCriteria)) > 5 Then
'remove the last 5 chars
stLinkCriteria = Left(stLinkCriteria, Len(stLinkCriteria) - 5)
Else
'select all records
stLinkCriteria = Empty
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria