Open forms using stLinkCriteria
Hi all,
I am a bit of a newbie to VBA and this is also my first online post to a forum, ever. So please be kind!
I have set up a custom form using a combo box to choose parameters. If there is a match in the related table I want it to open the form fvRiskA. If there is no match I would like it to display either a message box informing the user that there are no matches or another custom form that will display some text stating that their are no matches (fMsgNoCategory).
Here is the current variation of the code I have now:
Private Sub bSearchCategory_Click()
On Error GoTo Err_bSearchCategory_Click
Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[aCg]=" & "'" & Me![CatCrit] & "'"
If stLinkCriteria = stLinkCriteria Then
stDocName = "fvRiskA"
Else
stDocName = "fMsgNoCategory"
End If
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_bSearchCategory_Click:
Exit Sub
Err_bSearchCategory_Click:
MsgBox Err.Description
Resume Exit_bSearchCategory_Click
End Sub
I have looked at some similar posts on this and other forums but have not been able to find anything that relates to this specific situation. Any help would be greatly appreciated.
Thanking you in advance
Sopdet
Hi all,
I am a bit of a newbie to VBA and this is also my first online post to a forum, ever. So please be kind!
I have set up a custom form using a combo box to choose parameters. If there is a match in the related table I want it to open the form fvRiskA. If there is no match I would like it to display either a message box informing the user that there are no matches or another custom form that will display some text stating that their are no matches (fMsgNoCategory).
Here is the current variation of the code I have now:
Private Sub bSearchCategory_Click()
On Error GoTo Err_bSearchCategory_Click
Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[aCg]=" & "'" & Me![CatCrit] & "'"
If stLinkCriteria = stLinkCriteria Then
stDocName = "fvRiskA"
Else
stDocName = "fMsgNoCategory"
End If
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_bSearchCategory_Click:
Exit Sub
Err_bSearchCategory_Click:
MsgBox Err.Description
Resume Exit_bSearchCategory_Click
End Sub
I have looked at some similar posts on this and other forums but have not been able to find anything that relates to this specific situation. Any help would be greatly appreciated.
Thanking you in advance
Sopdet
Last edited: