473,890 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type mismatch error

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


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.OpenRecordse t("Security")

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

If IsNull(Me!txtus ername.Value) Then
MsgBox "The Username cannot be blank", vbExclamation, " Username
Me!txtusername. SetFocus
Exit Sub
varusername = Me!txtusername. Value
End If
If IsNull(Me!txtpa ssword.Value) Then
MsgBox "The Password field cannot be blank", vbExclamation,
"Password required"
Me!txtusername. SetFocus
Exit Sub
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.Set Focus
Exit Sub
varSec = rec(2)
Select Case varSec
Case 1
DoCmd.OpenForm "MainScreenInte rnal"
Case 2
DoCmd.OpenForm "MainScreenReha b"
Case 3
DoCmd.OpenForm "MainScreenReha bAdmin"
Case 4
DoCmd.OpenForm "MainScreenAdmi n"
Case Else
MsgBox "You do not have security to access these files. Please
contact the Administrator." , vbExclamation, "Access Denied"
End Select
End If

Set db = Nothing

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

End Sub

Nov 13 '05 #1
3 2046
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.


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

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,

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3
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("y ourTable")
For Each idx In tdf.Indexes
Debug.Print idx.Name, idx.Fields

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.


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

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

Similar topics

by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from the table datingnew the value of the ident field.
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to True. I then have an if statement to determine what to write to the screen depending on blnNoData. As long as the if statement is true (doesn't have to go to the else clause), the code runs fine. Otherwise, a type mismatch error is returned. In...
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column 14 (STDCOST). ---End Error Msg--- The STDCOST is set to decimal (28,14) and is a formatted in Access as a number, single with 14 decimal. I don't know why I would be getting a Type
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query that will run fine without any criteria but as soon as I add any criteria it gives a "Data type mismatch" error. As soon as I remove any criteria it runs perfectly. I know this query is based on another query but I have other processes based on...
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line 347: 'response.Write(sql2)
by: Brett | last post by:
I have a form that calls a method within a DLL. By clicking a button on the form, the DLL is instantiated and the SaveOutlookMessage() method invoked. The DLL code copies messages from Outlook to an HTML file. When I execute the EXE, which is only the form, and click the button, I get a "Type Mismatch" error on this line in the form: mailobj.SaveOutlookMessage() Any suggestions on why I'm getting the type mismatch error? --Form code
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The class has stuff initialized by calling a sub SetClass that wants some Word specific objects passed-in. If the user mistakingly uses the wrong object, say, uses an Excel object
by: jodyblau | last post by:
I have a database which works fine until I create and MDE file. Once I create the MDE, when I open a particular form I get a "Type Mismatch" error. Because its an MDE file, I can't step through the code to find out where the error is occuring; and (as I mentioned earlier) when I go back to the oriignal database the problem doesn't exist. Any ideas of what is going on here and how to fix it? Thanks,
by: zz12 | last post by:
Hello, is there a setting in IIS 5.0 that would quickly fix the following error?: Microsoft VBScript runtime (0x800A000D) Type mismatch It's strange because some of our .asp pages were working fine for the past years but recently our website was updated in that old folders were renamed and the new ones took on the existing name and was wondering why some our ..asp pages are now returning this error? I would think that since the code
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem has ended up in my lap i guess. This is the issue: There is an access database that pulls data from a list of excel spread sheets. This access database and excel files are stored on a server. When the database requests info from the excel file...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.