VB code to perform custom query of MS access table and display alert

G

ghadley_00

I have a MS access database which has entries (each of which has a name
field) and uses a form to make new entries. I would like to put
together code that will run when a new entry's name is entered that
does the following:

1) query the database to see if that name is already entered
2) if the name is already present, popup a msgbox telling the user the
name is already in the system, and in some way list the results of the
query (it is possible to have more than 1 record in the table to have
the same name)

I think I can do part 1 by running VB code that runs as afterupdate
event code, but I'm having trouble finding out how to connect to the
access database and perform the query.

Any help would be greatly appreciated.

George Hadley
(e-mail address removed)
 
G

guido

Create a query in the database to search for the names, then use the code to
re-write the SQL for the query (refered to as 'query1' below)
Dim strSQL As String
strSQL = "Select..." 'new query string
CurrentDb.QueryDefs("query1").SQL = strSQL 'assign SQL to query
If (CurrentDb.Recordsets("query1").RecordCount > 0) Then 'check for
records in query
'Open query1, or form linked to query1 here to display current info
End If
 

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