Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to find a record in a table from a form (Using DLookUp) 1

Status
Not open for further replies.

work4livinsean

Programmer
Mar 28, 2006
23
US
Hi Everyone,
I have a pretty extensive database but I need to do something very simple. I have created a form that has a submit button. When the submit button is clicked it takes all the fields (in the form) and puts them into a table (#1). I want to take one of those fields (lets say the name field) and compare it to a name field on another table (#2). If the name is found display a msgbox "Already found" and if not found do the process of adding the field to the table (#1). I cannot figure this out! Here is my code:

Dim findItPlease As String
findItPlease = Me.ApexID.Value '**Value from form
Dim didItFind As Variant '**Should it be variant?
didItFind = DLookup("[Name]", "tblActiveISD", "[APEX_ID] = " & findItPlease)
'**Name and APEX_ID are fields in table (#2)
If didItFind Is Nothing Then
MsgBox "Could not find, which is what I want"
'I have a SQL statement that adds the data successfully
Else
MsgBox "Found, do nothing"
End If
 
A name field implied text, if this is the case, you need quotes:
[tt]If Not IsNull(DLookup("[Name]", "tblActiveISD", "[APEX_ID] = '" & findItPlease & "'")) Then[/tt]
 
Thanks Remou, I have been looking for that answer for the last two days. I really appreciate it! Just FYI I do not need the 'NOT' for the If statement (I want it to run the other way). Thank you sooo much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top