textbox validation

  • Thread starter Thread starter vince
  • Start date Start date
V

vince

i've created a form for data entey proposes. to validate a
textbox i'd like to check if that value exists in one of my
tables within my database. in the lost_focus event
procedure i've included this code.

Private Sub IG_Client_ID_LostFocus()

SQL = "Select * from IG_DB where IG_Client_ID = "
SQL = SQL & Chr(39) & IG_Client_ID.Text & Chr(39)
Set RS = DB.OpenRecordset(SQL)
If RS.EOF Then
MsgBox "BRC ID does not exist!!!", vbExclamation, Error"
IG_Client_ID.Text = ""
IG_Client_ID.SetFocus
Exit Sub
End If
End Sub

in my main module i have this code.

Option Explicit
Public DB As Database
Public RS As Recordset
Public SQL As String

Sub Main()
Set DB = OpenDatabase("c:\IG_DB.mdb")
End Sub

i've used this code before in a vb application and it's
worked fine after i included some dao or ado components.
i'm getting a not defined type error when i declare my
variable DB as type Database. how can i get it to work in
access or is there a simplier way? thanks in advance.
 
I'm guessing that you're using ACCESS 2000 or higher. These versions do not
have a default reference set to the DAO library. Open VBE , select Tools |
References and select DAO library. Note that, if you're not going to use ADO
in your code, it's best to deselect the ADO library. ADO and DAO libraries
share some objects, so if you don't deselect ADO, you'll need to qualify
your references to DAO objects:

Dim RS As DAO.Recordset
 
By the way, it's easier to use the BeforeUpdate event instead of the
LostFocus event for doing control value validation.
 
Back
Top