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

  • Thread starter Thread starter ghadley_00
  • Start date Start date
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)
 
Your statement "connect to the access database" suggests your front end
isn't Access. Since you have the possibility more than one name that is the
same, I would create a small dialog form based on your same table. Use code
in the after update event of your name text boxes on your form like:

Dim strWhere as String
strWhere = "[FirstName]=""" & Me.txtFirstName & _
""" AND [LastName] = """ & Me.txtLastName & _
""" AND IDField <> " & Me.txtID
If DCount("*", "tblYourNameTable",strWhere) > 0 Then
DoCmd.OpenForm "frmYourDialogForm", , , strWhere
End If
 
Back
Top