Re: Return to form if query unmatched



On Jun 14, 1:19 pm, Richard <Rich...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Thanks Ko Zaw

I have put your code into the Open event on my form, but I am getting the
following error message upon opening the form:

Compile Error:
User-define type not defined

and the following text is then highlighted:
Mydbs As Database

Any ideas?

Thank you for your help.
--
Richard

"Ko Zaw" wrote:
On Jun 14, 4:26 am, Richard <Rich...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Thanks Doug

I have done some searching, but can't find out how to do what you are
suggesting. Can you help me further please.

Thank you.
--
Richard

"Douglas J. Steele" wrote:
In the form's Open event, you can check whether the query returns any rows.
If it doesn't pop up a message and set Cancel = True.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

"Richard" <Rich...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FEE65035-EA51-4F70-AF3D-E795EC93C6F5@xxxxxxxxxxxxxxxx
I have this query.

SELECT BOOKS.Number
FROM BOOKS
WHERE (((BOOKS.Number)<=[Enter the number:]))
GROUP BY BOOKS.Number
ORDER BY BOOKS.Number DESC;

What I want to do now is if the query returns no results, display a
message
then go to Main Manu form.

Can this be done?

I am using Windows XP and Access 2000.

Many thanks in advance.
--
Richard

Dear Richard,

Let me give you the code what Sir-Douglas talking about.

Private Sub Form_Open(Cancel As Integer)

Dim Mydbs As Database
Dim Myrst As Recordset
Dim MyRecCount As Long
Set Mydbs = CurrentDb
With Mydbs
Set Myrst = .OpenRecordset(Form.RecordSource)
MyRecCount = Myrst.RecordCount

If MyRecCount = 0 Then
MsgBox "This BOOK Number has " & MyRecCount & " no
Record." _
& vbCrLf & "You do not need to view."
Cancel = True
Else

MsgBox "This BOOK Number has " & MyRecCount & "
Record(s)."
End If
End With
Set Mydbs = Nothing
Set Myrst = Nothing

End Sub
__________________________________________________________
Ko Zaw

Hi Richard,

That mean you have to add more reference.
These reference can add from Code Windows > Tools Menu > Reference
button.
Check Marks to following and compile it.
- Visual Basic For Applications
- Microsoft Access xx.x Object Library (xx.x refer to digit)
- Microsoft Office xx.x Access Database Engine Object Library

It is always best to compile database before running.
And it is a practice.
______________________________
Bamar <NB: I've chaged My Nick Name from Ko Zaw to Bamar>

.