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

check the value of a text box against all other records in a field

Status
Not open for further replies.

Blitz

Technical User
Jul 7, 2000
171
US
I have a unbound textbox on a form. When a button is clicked I need it to check the value of that textbox against all of the records in a certain field and return an error(message box saying that value has already been used) if it matches and of the records. how can I do this?
 
Private Sub checknumber()
Dim wrk As Workspace
Dim dbs As Database
Dim rst As Recordset
Set wrk = DBEngine(0)
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(&quot;<tablename>&quot;, dbOpenTable)
wrk.BeginTrans

Do Until rst.EOF = True
If rst(&quot;<fieldname>&quot;) = textbox.Value Then
MsgBox &quot;This number has been used already. &quot;
Else
End If
rst.MoveNext
Loop
End Sub

Hope this helps.
Eradic8or
 
Thanks, I had to delete the dbOpenTable cause I was getting an error (not sure why) but once deleted it worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top