473,508 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL select statement with multiple variables

Can anyone tell me why this doesnt work? I have a form with two text
boxes (username and password) and this is the event I want to run after
the two boxes are filled in. (Click event for a button)

Dim user As String
Dim pass As String

If pass <> "" Then
pass = Me.Password
Else
pass = "yyyyyyyyyyyyy"
End If

If user <> "" Then
user = Me.Username
Else
user = "xxxxxxxxxxxxx"
End If

Dim db As Database
Dim rs As Recordset
Dim str As String
str = "Select * From [operators] Where [username]= '" & user & "'_ AND
[password] = '" & pass & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(str)
rs.MoveLast
If rs.RecordCount <> 0 Then
MsgBox "Match found"
Else
MsgBox "No Match found"
End If

Nov 13 '05 #1
3 9757
NO**********@azorinc.com wrote:
Can anyone tell me why this doesnt work? I have a form with two text
boxes (username and password) and this is the event I want to run after
the two boxes are filled in. (Click event for a button)

Dim user As String
Dim pass As String

If pass <> "" Then
pass = Me.Password
Else
pass = "yyyyyyyyyyyyy"
End If

If user <> "" Then
user = Me.Username
Else
user = "xxxxxxxxxxxxx"
End If

Dim db As Database
Dim rs As Recordset
Dim str As String
str = "Select * From [operators] Where [username]= '" & user & "'_ AND
[password] = '" & pass & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(str)
rs.MoveLast
If rs.RecordCount <> 0 Then
MsgBox "Match found"
Else
MsgBox "No Match found"
End If


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This:

str = "Select * From [operators] Where [username]= '" & user & "'_ AND
[password] = '" & pass & "'"

should be this:

str = "Select * From [operators] Where [username]= '" & user & _
"'" & AND [password] = '" & pass & "'"

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQjCH44echKqOuFEgEQK33ACdHu4O5JdF7WpDKgFoo7s4/2li1ToAoPrQ
6+LVzWOhhFZ32wl+GvxdWzGp
=UmyG
-----END PGP SIGNATURE-----
Nov 13 '05 #2
NO**********@azorinc.com wrote:
Can anyone tell me why this doesnt work? I have a form with two text
boxes (username and password) and this is the event I want to run after
the two boxes are filled in. (Click event for a button)

Dim user As String
Dim pass As String

If pass <> "" Then
pass = Me.Password
Else
pass = "yyyyyyyyyyyyy"
End If

If user <> "" Then
user = Me.Username
Else
user = "xxxxxxxxxxxxx"
End If

Dim db As Database
Dim rs As Recordset
Dim str As String
str = "Select * From [operators] Where [username]= '" & user & "'_ AND
[password] = '" & pass & "'"
Set db = CurrentDb
Set rs = db.OpenRecordset(str)
rs.MoveLast
If rs.RecordCount <> 0 Then
MsgBox "Match found"
Else
MsgBox "No Match found"
End If


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This:

str = "Select * From [operators] Where [username]= '" & user & "'_ AND
[password] = '" & pass & "'"

should be this:

str = "Select * From [operators] Where [username]= '" & user & _
"'" & AND [password] = '" & pass & "'"

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQjCH44echKqOuFEgEQK33ACdHu4O5JdF7WpDKgFoo7s4/2li1ToAoPrQ
6+LVzWOhhFZ32wl+GvxdWzGp
=UmyG
-----END PGP SIGNATURE-----
Nov 13 '05 #3
Ahhh. Brain Fart. Thanks!

Here is the completed code for anyone interested.

Dim user As String
Dim pswd As String

user = Me.Username
pswd = Me.Password

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim str As String

str = "SELECT * from Operators Where [Username] = '" & user & "' and
[Password] = '" & pswd & "';"
Set db = CurrentDb
Set rs = db.OpenRecordset(str)

If rs.RecordCount > 0 Then
DoCmd.Close

Else
MsgBox ("Invalid Username or Password!")
End If

Exit_Login_click:
Exit Sub

Err_Login_Click:
MsgBox ("You Must Enter a Username and Password!")
Resume Exit_Login_click

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9884
by: Greg Bryant | last post by:
Hi folks. I'm porting a cf site to php, everything's going very well, I like php much better (this, of course, being the correct forum to make that statement :). One problem I have is with...
0
10165
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
6
4270
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
1
2380
by: Neil H | last post by:
Hi All I am doing a multiple table and field database search, and my problem lies in the options that a user has. In each field, the user can specify a specific value or any value. I take each...
5
6887
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has...
3
8685
by: rallykarro | last post by:
Hi, How do I at the best way perform select statements over multiple databases? I have a couple of databases containing the same table definitions with diffrent data. Now I want them to act...
1
7232
by: syntego | last post by:
I am using DB2 V8 fixpack 10 and have the following issue: >From a User Defined Function, I can assign multiple variables in a single statement as follows: -- Get the first update transaction...
4
2250
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
1
21650
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
1
4866
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.