search button - msgbox on error - macro/vba?

M

Mac

I have a search button that prompts for info, then opens a form based on
criteria entered. If there are no records to be found based on that
criteria, I want the form to NOT open, and a msgbox to display instead. I
would prefer that I do this as a macro vs. vba since I'm not familiar with
vba just yet...if possible.

Also, I am not getting email notifications of replies, even after I choose
'Notify me of replies'... can I have replies sent directly to my email or do
I have to go through here? If you can email me directly...

(e-mail address removed)

Thank you,
Mac
 
P

Piet Linden

I have a search button that prompts for info, then opens a form based on
criteria entered.  If there are no records to be found based on that
criteria, I want the form to NOT open, and a msgbox to display instead.  I
would prefer that I do this as a macro vs. vba since I'm not familiar with
vba just yet...if possible.

Also, I am not getting email notifications of replies, even after I choose
'Notify me of replies'...  can I have replies sent directly to my emailor do
I have to go through here?  If you can email me directly...

(e-mail address removed)

Thank you,
Mac

Sorry, don't use Macros... Here's some simple code to do it...

Here's the code behind the button to open Form2 from Form1. Use the
wizard to build this... it will do all the work for you. (Open a
form, then you want to filter based on criteria.)

Private Sub cmdShowEventsForm_Click()
On Error GoTo Err_cmdShowEventsForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Events"

stLinkCriteria = "[DHSCaseNo]=" & "'" & Me![CaseNo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdShowEventsForm_Click:
Exit Sub

Err_cmdShowEventsForm_Click:
MsgBox Err.Description
Resume Exit_cmdShowEventsForm_Click

End Sub

In the form you are *opening*, put something like this:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No matching records... closing!", vbOKOnly +
vbInformation
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End Sub

Me.RecordsetClone.RecordCount gets a count of the records in the
form's underlying recordset. (the table/query the form is based on).
If there are no records, it will show the message box and close.
Otherwise it will just open.
 
J

Jack Leach

I would prefer that I do this as a macro vs. vba

Do yourself a gigantic favor and cut off your use of macros and learn the
vba... macros are pretty much useless, except the one named Autoexec (I know
I know, easier said than done, but you if you can do it you will not regret
it).

I have a search button that prompts for info, then opens a form based on
criteria entered. If there are no records to be found based on that
criteria, I want the form to NOT open, and a msgbox to display instead.

This is a relatively simple task, but we'll need some more info on how you
are going about it. What are you using to open the form? What are you using
to gather the criteria? There's a few ways to handle what you're looking
for, but will depend on these methods. Please provide whatever detailed
information you can for some guidance with the situation.

Also, I am not getting email notifications of replies, even after I choose
'Notify me of replies'... can I have replies sent directly to my email or do
I have to go through here?

The web interface to this newsgroup sucks. You can't depend on getting any
email notifications... pretend the option doesn't exist. Many people post
here complaining of this and other problems (posts not showing up for a few
days, site inaccessable, posts not showing at all, etc etc). If you plan to
spend some time here you might want to look into a newsreader app. There's
plenty out there. Some use AccessMonster.com as well, instead of MS's crappy
interface. (for the record, there doesn't seem to be anyone at MS that
intends to do anything about this, despite numerous numerous complaints from
people).





--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
M

Mac

Thank you for the vba, but I don't know where to put this. I'm not familiar
with vba at all. Where's a good place to start so I can understand why it
all does this?

Piet Linden said:
I have a search button that prompts for info, then opens a form based on
criteria entered. If there are no records to be found based on that
criteria, I want the form to NOT open, and a msgbox to display instead. I
would prefer that I do this as a macro vs. vba since I'm not familiar with
vba just yet...if possible.

Also, I am not getting email notifications of replies, even after I choose
'Notify me of replies'... can I have replies sent directly to my email or do
I have to go through here? If you can email me directly...

(e-mail address removed)

Thank you,
Mac

Sorry, don't use Macros... Here's some simple code to do it...

Here's the code behind the button to open Form2 from Form1. Use the
wizard to build this... it will do all the work for you. (Open a
form, then you want to filter based on criteria.)

Private Sub cmdShowEventsForm_Click()
On Error GoTo Err_cmdShowEventsForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Events"

stLinkCriteria = "[DHSCaseNo]=" & "'" & Me![CaseNo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdShowEventsForm_Click:
Exit Sub

Err_cmdShowEventsForm_Click:
MsgBox Err.Description
Resume Exit_cmdShowEventsForm_Click

End Sub

In the form you are *opening*, put something like this:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No matching records... closing!", vbOKOnly +
vbInformation
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End Sub

Me.RecordsetClone.RecordCount gets a count of the records in the
form's underlying recordset. (the table/query the form is based on).
If there are no records, it will show the message box and close.
Otherwise it will just open.
.
 

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