using If Then with a button

N

neenmarie

I have a button on a form to open a corresponding form. However, if there is
not corresponding data I'd like a message box to say that rather than having
a blank form open. How do I write the code for that? My current code is
simply:

Private Sub Command117_Click()

On Error GoTo Err_Command117_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FEASIBILITY SIGN OFF FORM"

stLinkCriteria = "[QuoteNumber]=" & Me![AutoID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command117_Click:
Exit Sub

Err_Command117_Click:
MsgBox Err.Description
Resume Exit_Command117_Click

End Sub
 
C

CyberDwarf

In the load event for the report,try this:-

if not me.hasdata then
msgbox..... 'Or whatever you want to do
end if


HTH

neenmarie said:
I have a button on a form to open a corresponding form. However, if there is
not corresponding data I'd like a message box to say that rather than having
a blank form open. How do I write the code for that? My current code is
simply:

Private Sub Command117_Click()

On Error GoTo Err_Command117_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FEASIBILITY SIGN OFF FORM"

stLinkCriteria = "[QuoteNumber]=" & Me![AutoID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command117_Click:
Exit Sub

Err_Command117_Click:
MsgBox Err.Description
Resume Exit_Command117_Click

End Sub
 
N

neenmarie

Thank you for your response.
When I tried using the if statement in the load event, I had an error with
the 'hasdata'. The VB didn't recognize it.


CyberDwarf said:
In the load event for the report,try this:-

if not me.hasdata then
msgbox..... 'Or whatever you want to do
end if


HTH

neenmarie said:
I have a button on a form to open a corresponding form. However, if there is
not corresponding data I'd like a message box to say that rather than having
a blank form open. How do I write the code for that? My current code is
simply:

Private Sub Command117_Click()

On Error GoTo Err_Command117_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FEASIBILITY SIGN OFF FORM"

stLinkCriteria = "[QuoteNumber]=" & Me![AutoID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command117_Click:
Exit Sub

Err_Command117_Click:
MsgBox Err.Description
Resume Exit_Command117_Click

End Sub
 
K

Klatuu

One way would be to do a DCount using the same filtering criteria that the
form you want to open would use.

If DCount("*", "SameRecordsetAsForm", "SameFilteringCriteria") = 0 Then
MsgBox "No Data Available"
Else
Docmd.OpenForm....
End If

neenmarie said:
I have a button on a form to open a corresponding form. However, if there is
not corresponding data I'd like a message box to say that rather than having
a blank form open. How do I write the code for that? My current code is
simply:

Private Sub Command117_Click()

On Error GoTo Err_Command117_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FEASIBILITY SIGN OFF FORM"

stLinkCriteria = "[QuoteNumber]=" & Me![AutoID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command117_Click:
Exit Sub

Err_Command117_Click:
MsgBox Err.Description
Resume Exit_Command117_Click

End Sub
 
Top