Solved

any ideas on how to compare input with database?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

710 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