Help I'm stuck!

  • Thread starter 2Blessed4Stress
  • Start date
2

2Blessed4Stress

I'm an amature programmer so please be very basic. I have code in a form on
the "on open" event to give a message if no results are present.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "THERE ARE NO RESULTS FOR YOUR SEARCH." _
, vbInformation, "No Records"
Cancel = True

End If

This works fine but I need to run a macro (mc_DescATW GROUPEQP.New Search)
after the user hits "ok" from the error message. Can someone please tell me
what to do?
 
D

Dirk Goldgar

2Blessed4Stress said:
I'm an amature programmer so please be very basic. I have code in a form
on
the "on open" event to give a message if no results are present.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "THERE ARE NO RESULTS FOR YOUR SEARCH." _
, vbInformation, "No Records"
Cancel = True

End If

This works fine but I need to run a macro (mc_DescATW GROUPEQP.New Search)
after the user hits "ok" from the error message. Can someone please tell
me
what to do?


It might be as simple as adding the line

DoCmd.RunMacro "mc_DescATW GROUPEQP.New Search"

.... immediately after the "Cancel = True" line.
 
2

2Blessed4Stress

This is what I have....

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "THERE ARE NO RESULTS FOR YOUR SEARCH."
, vbInformation, "No Records"
Cancel = True
DoCmd.RunMacro "mc_DescATW GROUPEQP.New Search"

and I get a Compile error: Syntax Error
 
D

Dirk Goldgar

2Blessed4Stress said:
This is what I have....

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "THERE ARE NO RESULTS FOR YOUR SEARCH."
, vbInformation, "No Records"
Cancel = True
DoCmd.RunMacro "mc_DescATW GROUPEQP.New Search"

and I get a Compile error: Syntax Error


If that's exactly what you have, then you haven't continuted the MsgBox
statement correctly onto the second line. Try this:

'----- start of corrected code snippet -----
Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.RecordCount = 0 Then

MsgBox "THERE ARE NO RESULTS FOR YOUR SEARCH.", _
vbInformation, "No Records"

Cancel = True

DoCmd.RunMacro "mc_DescATW GROUPEQP.New Search"

End If

End Sub
'----- end of corrected code snippet -----

I've spaced that out a bit to make it easier to read, and added "End If" and
"End Sub" lines just to make the snippet complete, but the main point is the
line-continuation character "_" at the end of the first line of the MsgBox
statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top