Solved

any ideas on how to compare input with database?

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now