Link to home
Start Free TrialLog in
Avatar of stefanne
stefanne

asked on

any ideas on how to compare input with database?

hi! i'm trying to write a program here where a user will enter his identity number and VB will compare the number with the existing number in the database... i'm using Access. How am i going to do that? Considering that when the user clicks onthe submit button, VB will call the database and compare the ID number. anybody can give me that code?
ASKER CERTIFIED SOLUTION
Avatar of cnealy
cnealy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gencross
gencross

This may not be exact, but it is pretty close.  You will have to change you table and field names.  Hope this helps.

Dim objDBConn as ADODB.Connection    
dim rstTemp as adodb.recordset

Set objDBConn = New ADODB.Connection
   
With objDBConn
     .CursorLocation = adUseClient
     .Provider = "Microsoft.Jet.OLEDB.3.51;jet oledb"
     .Open "c:\DB.mdb"
end with

set rstTemp = "SELECT Count(*) AS RecCount FROM table Where UserID = " & UserID

if rstTemp!RecCount > 0 then
    'ID matches
else
    'ID does not match
end if

rsttemp.close

objdbconn.close
Recordcount is not a reliable one. I would prefer to use the BOF and EOF properties. Also Use TypeConversion function since the value from textbox is of type string only.

The code is

Private sub Command1_Click()
  If rs.State = 1 Then rs.Close
  rs.Open "SELECT User_Name FROM table_name where id=" & CLng(Text1.text), cn
  If Not (rs.EOF And rs.BOF) Then
    msgbox "Welcome" & rs("User_Name")
  Else
    msgbox "Authorization Required" & vbCrLf & "Please Try again", vbExclamation
  End If
End Sub


###########################
for more info about BOF and EOF properties

http://msdn.microsoft.com/library/en-us/ado270/htm/mdprobof.asp
#############################

All the Best.
KCM
Avatar of DanRollins
Hi stefanne,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept cnealy's comment(s) as an answer.

stefanne, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Moving to the paq

kb
Experts Exchange Moderator