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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing info in a form to info in a table

Status
Not open for further replies.

hwagner

Programmer
Jul 20, 2005
11
US
I want to know if there is a way in SQL to write a procedure that takes the information that is typed in the form and checks it against what is in the table to see if its already exists. And if it does exists in the table, I want it to fill in the rest of the feilds with what is already in the table on the form.

Please help.

Thank you
 
You could do something like this: (change names where appropriate)(I have the user select from a combobox - it avoids typing errors)
Private Sub notebox_AfterUpdate()
Dim DB As Database
Dim RS As Recordset
Dim strWhere As String
Dim SQLText
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("YourtableName", dbOpenDynaset)
strWhere = "[TableField] = " & Chr(34) & Me![ComboBoxName] & Chr(34)
RS.FindFirst strWhere
If RS.NoMatch Then
MsgBox "No match found"
Else
SQLText = "Select * From [TableName] Where [TableName] = " & Chr(34) & Me![ComboBoxName] & Chr(34)
Forms![YourFormName].RecordSource = SQLText
Me![ComboBoxName] = Null
End If
RS.Close
DB.Close
Set RS = Nothing
Set DB = Nothing
End Sub

If CombBox value is numeric then:
strWhere = "[TableField] = " & Me![ComboBoxName]
Same for SQLText statement
 
Thank you so much for ur help ill see if that works. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top