Find Record based on combo box

Georgina

Registered User.
Local time
Today, 14:49
Joined
Jan 25, 2001
Messages
19
Hi

I have a search form with 1 combo box and a button which when the user inputs an invoice number and clicks the button, a main form is opened for that particular record.

The problem I have is to display an error message before the main form opens if the user has either left the combo box blank or they have input an invoice number that doesn't exist.

This feels like it should be easy......!

Thanks for any help

Georgina
 
not so difficult.. I can help you using DAO..

you can use this code:

Dim db As DAO.Database
Dim oTD As DAO.TableDef
Dim counter as Integer

Set db = CurrentDb
Set oTD = db.TableDefs(yourTableName)
counter = oTD.RecordCount

if combobox.value="" then
MsgBox "ERROR: empty combobox!!", vbcritical, "ERROR"
elseif combobox.value > counter then
MsgBox "ERROR: can't find the specified record; the record does not exist", vbcritical, "ERRORE
end if


P.S.:
yourTableName is the name of the table which the form you open is associated to. (the table of the record that you want to find)
 
or..

you can run a query with COUNT and similary get the count of the records.. as you prefer!!
 
Hi

Thanks for your reply - I must be missing the point again though - I have put the code behind my combo box, but now get an error message of User-defined type not defined for


Dim db As DAO.Database
Dim oTD As DAO.TableDef
Dim counter As Integer

Any more ideas???

Thanks

Georgina
 

Users who are viewing this thread

Back
Top Bottom