By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

Type mismatch error

P: n/a
Hi There,
I have the following code and when I try to run it, I get a type mismatch
error.
I would really appreciate your help with this.
Thanks kindly,

smriti
---

Private Sub cmdOK_Click()

Dim strMsg As String
Dim varusername As String
Dim varSec As Byte
Dim varPW As String
Dim db As Database
Dim rec As Recordset

Set db = CurrentDb()
Set rec = db.OpenRecordset("Security")

strMsg = "User ID is incorrect or could not be found. Try again"
strMsg = strMsg & Chr(13) & "If this persists, contact the
Administrator."

If IsNull(Me!txtusername.Value) Then
MsgBox "The Username cannot be blank", vbExclamation, " Username
required"
Me!txtusername.SetFocus
Exit Sub
Else
varusername = Me!txtusername.Value
End If
If IsNull(Me!txtpassword.Value) Then
MsgBox "The Password field cannot be blank", vbExclamation,
"Password required"
Me!txtusername.SetFocus
Exit Sub
Else
varPW = Me!txtpassword.Value
End If
rec.Index = "username"
rec.Seek "=", varusername
Exit Sub
If varPW <> rec(1) Then
MsgBox "Please retype your password. If this problem persists,
contact the Administrator.", vbExclamation, "Incorrect Password"
txtpassword.SetFocus
Exit Sub
Else
varSec = rec(2)
Select Case varSec
Case 1
DoCmd.OpenForm "MainScreenInternal"
Case 2
DoCmd.OpenForm "MainScreenRehab"
Case 3
DoCmd.OpenForm "MainScreenRehabAdmin"
Case 4
DoCmd.OpenForm "MainScreenAdmin"
Case Else
MsgBox "You do not have security to access these files. Please
contact the Administrator.", vbExclamation, "Access Denied"
End Select
End If

rec.Close
Set db = Nothing

Me.Visible = False
'DoCmd.Close acForm, "LoginForm"

End Sub

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Smriti

You need to specify where the error is occuring. When I have a problem
like this I comment out all error trapping and then step through the
code in debug mode. The purpose of removing error trapping is so you
can see where the code bombs out. Error trapping is for when your
application is already in production and your program can exit (error
out something unexpected) gracefully. So after removing all error
trapping you place a breakpoint at the beginning of the executable code
(not the dim statements) and then step through the code using the F8
key. Note the line of code where it errors out. Then post that
information. Then you can be further assisted.

To set a break point you click on/in the left gray margin on the line
where you want to start debugging. Clicking on the left gray margin on
the line you want to have a breakpoint will place a red dot on the gray
margin and highlight that entire line of code in red. You can only set
a breakpoint where there is an uncommented line of code. Then you just
press the F8 key repeatedly to step through your code.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #2

P: n/a


Hi Rich,
Thanks for your response. I see the error occuring in line 33,

rec.Index = "Username"

The error I get is 'Username' is not an index in this table.

What does this mean and how can I resolve it?
Thanks so much for the help!

Take care,
Smriti

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3

P: n/a
Hello again Smriti,

Well, my first question is "what are you looking to accomplish with this
sub that you need to set an index?

Next, you can loop through the index collection of your table to see
what indexes you do have:

Dim db As DAO.Database
Dim idx As DAO.Index
Dim tdf As DAO.TableDef
Set db = CurrentDb
Set tdf = db.TableDefs("yourTable")
For Each idx In tdf.Indexes
Debug.Print idx.Name, idx.Fields
Next

This snipet will tell you what indexes you do have and what fields they
belong to. If you want to set an index you have to set it to a TableDef
Object. I don't believe you can set an Index to a Recordset Object.
That is what is causing your problem in the first place.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.