Solved

any ideas on how to compare input with database?

Posted on 2002-03-18
5
171 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

776 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