Forms and Records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to Prevent a form (Control source based on a query) from opening
if no records exist. I am using the following criteria in the query to search
for names.

Like [Enter Sender's First Name: ] & "*".

If there is no record for the search name entered then i would like to print
a message such as NO RECORDS FOUND and stop the form from opening.

Can you please help me. Thanks
Faz
 
Hi Faz

Use the form's OnOpen event like this

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "Some Message", vbOKOnly, "No records found"
End If
End Sub


Hope this helps
 
Hi Wayne, I put this code in the form"Look-up Name Form" and nothing happens.
A blank form still opens but it is showing record 1, so i changed the =0 to
<=1 but still nothing. Am i missing something?
Wayne-I-M said:
Hi Faz

Use the form's OnOpen event like this

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "Some Message", vbOKOnly, "No records found"
End If
End Sub


Hope this helps

--
Wayne
Manchester, England.



Faz said:
I would like to Prevent a form (Control source based on a query) from opening
if no records exist. I am using the following criteria in the query to search
for names.

Like [Enter Sender's First Name: ] & "*".

If there is no record for the search name entered then i would like to print
a message such as NO RECORDS FOUND and stop the form from opening.

Can you please help me. Thanks
Faz
 
Hi Faz

Soory for the delay in getting back to you - I have been out of the office
and have to go out again now.

Have a look at Alan Brown' in depth look at this problem.
http://groups.google.co.uk/group/mi...3327e4213fd/cb5c777c92f1bacd#cb5c777c92f1bacd

Good luck

--
Wayne
Manchester, England.



Faz said:
Hi Wayne, I put this code in the form"Look-up Name Form" and nothing happens.
A blank form still opens but it is showing record 1, so i changed the =0 to
<=1 but still nothing. Am i missing something?
Wayne-I-M said:
Hi Faz

Use the form's OnOpen event like this

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "Some Message", vbOKOnly, "No records found"
End If
End Sub


Hope this helps

--
Wayne
Manchester, England.



Faz said:
I would like to Prevent a form (Control source based on a query) from opening
if no records exist. I am using the following criteria in the query to search
for names.

Like [Enter Sender's First Name: ] & "*".

If there is no record for the search name entered then i would like to print
a message such as NO RECORDS FOUND and stop the form from opening.

Can you please help me. Thanks
Faz
 
Faz said:
Hi Wayne, I put this code in the form"Look-up Name Form" and nothing
happens. A blank form still opens but it is showing record 1, so i
changed the =0 to <=1 but still nothing. Am i missing something?
"Wayne-I-M" wrote:

Did you also set the OnOpen event property to [EventProcedure]? That is what
makes the code run.
 
WOW..It Works, Thank you so much.
Faz

Rick Brandt said:
Faz said:
Hi Wayne, I put this code in the form"Look-up Name Form" and nothing
happens. A blank form still opens but it is showing record 1, so i
changed the =0 to <=1 but still nothing. Am i missing something?
"Wayne-I-M" wrote:

Did you also set the OnOpen event property to [EventProcedure]? That is what
makes the code run.
 

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

Back
Top