PC Review


Reply
Thread Tools Rate Thread

Data Type mismatch error?

 
 
=?Utf-8?B?Q2FybGVl?=
Guest
Posts: n/a
 
      16th Apr 2004
Hi there

I have logon box which when the user enters a username and password a form will open. The code is below. this worked well in AC97, but in Access XP, i am getting a database type mismatch on the following line

Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM tblLogon WHERE Username = Username AND Password = Password;"

Can anyone help me on this one

Thank you in advance
Private Sub cmdVerify_Click(
'verifies the user name and password are correct. if they are, access is provided to datatables, if not, the
'access is denie

'On Error GoTo click_err
Dim dbsMaster As Databas
Dim rstLogon As Recordse

Set dbsMaster = CurrentDb(
Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM tblLogon WHERE Username = Username AND Password = Password;"

With rstLogo
If Not rstLogon.RecordCount = 0 The
Do While Not .EO
If rstLogon!Username = Username And rstLogon!Password = Password The

DoCmd.Close acForm, "frmLogon
DoCmd.Close acForm, "frmAdministration
DoCmd.OpenForm "frmDataTableEditable

ElseIf rstLogon!Username <> Username And rstLogon!Password <> Password The
.MoveNex

Els
MsgBox "The Username or Password entered is incorrect.", vbOKOnly, "Logon Error!
DoCmd.Close acForm, "frmLogon
End I
Loo
End I
End Wit
If Username <> rstLogon.RecordCount = -1 The
MsgBox "Sorry! The information you entered is incorrect."
& Chr(13) & Chr(13) & "Please contact your database administrator", vbOKOnly, "Logon Error!
DoCmd.Close acForm, "frmLogon
End I
rstLogon.Clos

'click_err
' Exit Su
End Su

 
Reply With Quote
 
 
 
 
Phil Hunt
Guest
Posts: n/a
 
      16th Apr 2004
common problem. You need to get a pair of double quote around the username
and password (the data, not the field name). I won't show you the code,
because it is confusing. But tha's the problem.
"Carlee" <(E-Mail Removed)> wrote in message
news:BFD26256-0085-4619-993E-(E-Mail Removed)...
> Hi there,
>
> I have logon box which when the user enters a username and password a form

will open. The code is below. this worked well in AC97, but in Access XP,
i am getting a database type mismatch on the following line:
>
> Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM tblLogon WHERE

Username = Username AND Password = Password;")
>
> Can anyone help me on this one?
>
> Thank you in advance,
> Private Sub cmdVerify_Click()
> 'verifies the user name and password are correct. if they are, access is

provided to datatables, if not, then
> 'access is denied
>
> 'On Error GoTo click_err:
> Dim dbsMaster As Database
> Dim rstLogon As Recordset
>
> Set dbsMaster = CurrentDb()
> Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM tblLogon WHERE

Username = Username AND Password = Password;")
>
> With rstLogon
> If Not rstLogon.RecordCount = 0 Then
> Do While Not .EOF
> If rstLogon!Username = Username And rstLogon!Password = Password

Then
>
> DoCmd.Close acForm, "frmLogon"
> DoCmd.Close acForm, "frmAdministration"
> DoCmd.OpenForm "frmDataTableEditable"
>
> ElseIf rstLogon!Username <> Username And rstLogon!Password <>

Password Then
> .MoveNext
>
> Else
> MsgBox "The Username or Password entered is incorrect.",

vbOKOnly, "Logon Error!"
> DoCmd.Close acForm, "frmLogon"
> End If
> Loop
> End If
> End With
> If Username <> rstLogon.RecordCount = -1 Then
> MsgBox "Sorry! The information you entered is incorrect." _
> & Chr(13) & Chr(13) & "Please contact your database

administrator", vbOKOnly, "Logon Error!"
> DoCmd.Close acForm, "frmLogon"
> End If
> rstLogon.Close
>
> 'click_err:
> ' Exit Sub
> End Sub
>



 
Reply With Quote
 
John Spencer (MVP)
Guest
Posts: n/a
 
      18th Apr 2004
Access XP defaults to using ADO vice DAO. So you need a reference to the DAO
library. To do that
Open any module
Select Tools: References
Find and Check Microsoft DAO 3.6(???) Object Library
(Not positive on the version number, but I think it is correct)

Once you have that you need to either remove the reference to ADO (you are
probably not using that library) or you need to specify which library you are
using in specific cases.

Dim dbsMaster as DAO.Database
Dim rstLogon as DAO.Recordset

Also, I am suspicious of your SQL statement. I think it should read

"SELECT * FROM tblLogon WHERE Username =" & Chr(34) & me.Username & Chr(34) & "
AND Password =" & Chr(34) & Me.Password & Chr(34)

Of course you could do all this with simpler code, that wouldn't even require
opening a recordset.

Private Sub cmdVerify_Click()
If DCount("*","tblLogon", _
"Username =" & Chr(34) & me.Username & Chr(34) & _
" AND Password =" & Chr(34) & Me.Password & Chr(34)) = 0 THEN

'Your message/actions here for invalid logon
Else
'Successful logon actions here
End If
End Sub

Your current SQL statement is returning every record in tblLogon and that is why
you have to step through every record in the recordset until you get a match.

That would
Carlee wrote:
>
> Hi there,
>
> I have logon box which when the user enters a username and password a form will open. The code is below. this worked well in AC97, but in Access XP, i am getting a database type mismatch on the following line:
>
> Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM tblLogon WHERE Username = Username AND Password = Password;")
>
> Can anyone help me on this one?
>
> Thank you in advance,
> Private Sub cmdVerify_Click()
> 'verifies the user name and password are correct. if they are, access is provided to datatables, if not, then
> 'access is denied
>
> 'On Error GoTo click_err:
> Dim dbsMaster As Database
> Dim rstLogon As Recordset
>
> Set dbsMaster = CurrentDb()
> Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM tblLogon WHERE Username = Username AND Password = Password;")
>
> With rstLogon
> If Not rstLogon.RecordCount = 0 Then
> Do While Not .EOF
> If rstLogon!Username = Username And rstLogon!Password = Password Then
>
> DoCmd.Close acForm, "frmLogon"
> DoCmd.Close acForm, "frmAdministration"
> DoCmd.OpenForm "frmDataTableEditable"
>
> ElseIf rstLogon!Username <> Username And rstLogon!Password <> Password Then
> .MoveNext
>
> Else
> MsgBox "The Username or Password entered is incorrect.", vbOKOnly, "Logon Error!"
> DoCmd.Close acForm, "frmLogon"
> End If
> Loop
> End If
> End With
> If Username <> rstLogon.RecordCount = -1 Then
> MsgBox "Sorry! The information you entered is incorrect." _
> & Chr(13) & Chr(13) & "Please contact your database administrator", vbOKOnly, "Logon Error!"
> DoCmd.Close acForm, "frmLogon"
> End If
> rstLogon.Close
>
> 'click_err:
> ' Exit Sub
> End Sub

 
Reply With Quote
 
William Hansen
Guest
Posts: n/a
 
      19th Apr 2004
I have the same problem. I also have code that checks if
there is no found record:

"If rstAuth.NoMatch = False Then"

which recieves the compile error "Method or
Data Type not found." All this worked in 97. I suspect
the problem is a compatability library is needed, but I
do not know what and where it is. I am using "Microsoft
DAO 3.6 Object Library"

Can anyone help?
Thank you,
Bill Hansen
>-----Original Message-----
>Hi there,
>
>I have logon box which when the user enters a username

and password a form will open. The code is below. this
worked well in AC97, but in Access XP, i am getting a
database type mismatch on the following line:
>
> Set rstLogon = dbsMaster.OpenRecordset("SELECT * FROM

tblLogon WHERE Username = Username AND Password =
Password;")
>
>Can anyone help me on this one?
>
>Thank you in advance,
>Private Sub cmdVerify_Click()
>'verifies the user name and password are correct. if

they are, access is provided to datatables, if not, then
>'access is denied
>
>'On Error GoTo click_err:
> Dim dbsMaster As Database
> Dim rstLogon As Recordset
>
> Set dbsMaster = CurrentDb()
> Set rstLogon = dbsMaster.OpenRecordset("SELECT *

FROM tblLogon WHERE Username = Username AND Password =
Password;")
>
> With rstLogon
> If Not rstLogon.RecordCount = 0 Then
> Do While Not .EOF
> If rstLogon!Username = Username And rstLogon!

Password = Password Then
>
> DoCmd.Close acForm, "frmLogon"
> DoCmd.Close acForm, "frmAdministration"
> DoCmd.OpenForm "frmDataTableEditable"
>
> ElseIf rstLogon!Username <> Username And

rstLogon!Password <> Password Then
> .MoveNext
>
> Else
> MsgBox "The Username or Password entered is

incorrect.", vbOKOnly, "Logon Error!"
> DoCmd.Close acForm, "frmLogon"
> End If
> Loop
> End If
> End With
> If Username <> rstLogon.RecordCount = -1 Then
> MsgBox "Sorry! The information you entered

is incorrect." _
> & Chr(13) & Chr(13) & "Please contact your

database administrator", vbOKOnly, "Logon Error!"
> DoCmd.Close acForm, "frmLogon"
> End If
> rstLogon.Close
>
>'click_err:
> ' Exit Sub
> End Sub
>
>.
>

 
Reply With Quote
 
William Hansen
Guest
Posts: n/a
 
      19th Apr 2004
This solves my problem(s) Thanks Bill Hansen
>-----Original Message-----
>Access XP defaults to using ADO vice DAO. So you need a

reference to the DAO
>library. To do that
> Open any module
> Select Tools: References
> Find and Check Microsoft DAO 3.6(???) Object Library
>(Not positive on the version number, but I think it is

correct)
>
>Once you have that you need to either remove the

reference to ADO (you are
>probably not using that library) or you need to specify

which library you are
>using in specific cases.
>
>Dim dbsMaster as DAO.Database
>Dim rstLogon as DAO.Recordset
>
>Also, I am suspicious of your SQL statement. I think it

should read
>
>"SELECT * FROM tblLogon WHERE Username =" & Chr(34) &

me.Username & Chr(34) & "
>AND Password =" & Chr(34) & Me.Password & Chr(34)
>
>Of course you could do all this with simpler code, that

wouldn't even require
>opening a recordset.
>
>Private Sub cmdVerify_Click()
> If DCount("*","tblLogon", _
> "Username =" & Chr(34) & me.Username & Chr(34) & _
> " AND Password =" & Chr(34) & Me.Password & Chr

(34)) = 0 THEN
>
> 'Your message/actions here for invalid logon
> Else
> 'Successful logon actions here
> End If
>End Sub
>
>Your current SQL statement is returning every record in

tblLogon and that is why
>you have to step through every record in the recordset

until you get a match.
>
>That would
>Carlee wrote:
>>
>> Hi there,
>>
>> I have logon box which when the user enters a username

and password a form will open. The code is below. this
worked well in AC97, but in Access XP, i am getting a
database type mismatch on the following line:
>>
>> Set rstLogon = dbsMaster.OpenRecordset("SELECT *

FROM tblLogon WHERE Username = Username AND Password =
Password;")
>>
>> Can anyone help me on this one?
>>
>> Thank you in advance,
>> Private Sub cmdVerify_Click()
>> 'verifies the user name and password are correct. if

they are, access is provided to datatables, if not, then
>> 'access is denied
>>
>> 'On Error GoTo click_err:
>> Dim dbsMaster As Database
>> Dim rstLogon As Recordset
>>
>> Set dbsMaster = CurrentDb()
>> Set rstLogon = dbsMaster.OpenRecordset("SELECT *

FROM tblLogon WHERE Username = Username AND Password =
Password;")
>>
>> With rstLogon
>> If Not rstLogon.RecordCount = 0 Then
>> Do While Not .EOF
>> If rstLogon!Username = Username And rstLogon!

Password = Password Then
>>
>> DoCmd.Close acForm, "frmLogon"
>> DoCmd.Close acForm, "frmAdministration"
>> DoCmd.OpenForm "frmDataTableEditable"
>>
>> ElseIf rstLogon!Username <> Username And

rstLogon!Password <> Password Then
>> .MoveNext
>>
>> Else
>> MsgBox "The Username or Password entered

is incorrect.", vbOKOnly, "Logon Error!"
>> DoCmd.Close acForm, "frmLogon"
>> End If
>> Loop
>> End If
>> End With
>> If Username <> rstLogon.RecordCount = -1 Then
>> MsgBox "Sorry! The information you

entered is incorrect." _
>> & Chr(13) & Chr(13) & "Please contact your

database administrator", vbOKOnly, "Logon Error!"
>> DoCmd.Close acForm, "frmLogon"
>> End If
>> rstLogon.Close
>>
>> 'click_err:
>> ' Exit Sub
>> End Sub

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Type mismatch error B. Meincke Microsoft Access Form Coding 3 15th Feb 2009 12:47 AM
Error data type mismatch Eric Microsoft Access 2 15th Aug 2006 09:51 AM
Data Type Mismatch Error =?Utf-8?B?ag==?= Microsoft Access 2 20th Jun 2006 12:51 AM
data-type mismatch...Why am I getting this error??? Angi Microsoft Access Form Coding 2 5th May 2005 03:41 PM
ADO Data Type Mismatch error Lucky Microsoft Access VBA Modules 1 16th Aug 2003 02:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:24 PM.