Solved

any ideas on how to compare input with database?

Posted on 2002-03-18
5
173 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:stefanne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
cnealy earned 50 total points
ID: 6877482
"Select * from table where ID = " & Textbox.Text

If recordset.count > 0 Then
 'the ID matches
Else
 'it doesn't match
End If
0
 
LVL 4

Expert Comment

by:gencross
ID: 6877653
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
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6884155
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
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7634137
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
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7665961
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question