473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Run time error 3464 Type mismatch in criteria expression

Hello, I am trying to fix a db that was written by someone else. I had to change a key field (GroupNo) in a table from Numeric to Text and am now coming up with data type mismatch. In this part of the code keyNow has been defined as Variant = 0. Error is thrown on the DLookup line.


Expand|Select|Wrap|Line Numbers
  1. Public Function doQueryDefSQL(ByRef fromWhere As String, Optional keyNow As Variant = 0) As Boolean
  2. ...
  3. If fromWhere <> "Clicked" Then   'Opened
  4.       If Nz(DCount("*", "Accounts", "Location='0'"), 0) = 2 Then
  5.          keyNow = DLookup("GroupNo", "Accounts", "GroupNo<>0")
  6.       Else
  7.          keyNow = getDefault("GroupNo")
  8.       End If
  9.    End If
...


Much thanks!
Shar
Jul 2 '15 #1

✓ answered by Stewart Ross

To rule out problems with your definition of keyNo simply change its definition from variant to string.

You can check whether DLookup is working as expected using the Immediate window in the VBA editor to execute a print statement for the DLookup itself:

? DLookup("GroupNo", "Accounts", "GroupNo<>'0'")

This should not give a type mismatch error. If it does, leave out the Where clause and see what happens:

? DLookup("GroupNo", "Accounts")

Without the Where clause this should return the GroupNo from the first row of the Accounts table.

A type mismatch normally arises when an argument of a specific type is not supplied in compatible form - e.g. the where clause structured for a numeric comparison when a text comparison is required, or a null value being supplied when a defined type such as a string or integer has been specified.

Difficult to know what else to advise until you can test the suggestions above.

-Stewart

6 2282
Stewart Ross
2,545 Expert Mod 2GB
If you have redefined GroupNo as a text field then the Where clause of the DLookup has to be modified slightly. Just as in a SQL Where clause, text values must be enclosed in single quotes:
Expand|Select|Wrap|Line Numbers
  1. keyNo = DLookup("GroupNo", "Accounts", "GroupNo<>'0'")
As you mention that your keyNo variable is defined as a variant type you may find that it is set as a text type when returned from the DLookup. This may not matter, as Access will convert types on the fly where needed, but you should at least be aware of the possibility, to avoid further type mismatches occurring in your code.

If you need keyNo to be a numeric value you could change its type to Long, unless the range of the GroupNo field values exceeds what a long integer can represent.

-Stewart
Jul 2 '15 #2
Hi Stewart,
I had already tried that but still received an error. Yes I had found that because keyNow is a Variant that Access will convert based on the value. GroupNo will always be data type TEXT (String) so for instance, whether keyNow value is 0 (varientInteger) or 2540 (variantDouble or variantLong) or K006 (variantString) or whatever, I think it is erring because it's not an exact data type match, thus the reason for the "mismatch" error. So I'm thinking should I always try to convert keyNow to a String and then it should always match and hopefully will not err? What do you think? If so, what would be the best way to do that?

Again much thanks! I'm in urgent need of some help today as this is holding up a major project.
Jul 2 '15 #3
Oh and I also tried to change the ByRef for keyNow from variant to string but I must have done it wrong because I'm still getting errors.
Jul 2 '15 #4
Stewart Ross
2,545 Expert Mod 2GB
To rule out problems with your definition of keyNo simply change its definition from variant to string.

You can check whether DLookup is working as expected using the Immediate window in the VBA editor to execute a print statement for the DLookup itself:

? DLookup("GroupNo", "Accounts", "GroupNo<>'0'")

This should not give a type mismatch error. If it does, leave out the Where clause and see what happens:

? DLookup("GroupNo", "Accounts")

Without the Where clause this should return the GroupNo from the first row of the Accounts table.

A type mismatch normally arises when an argument of a specific type is not supplied in compatible form - e.g. the where clause structured for a numeric comparison when a text comparison is required, or a null value being supplied when a defined type such as a string or integer has been specified.

Difficult to know what else to advise until you can test the suggestions above.

-Stewart
Jul 2 '15 #5
Okay great. I will try and let you know what happens. Thank you!
Jul 2 '15 #6
Thanks Stewart. The single quotes fixed one issue but now errors are occurring in other parts of the code. :( I'll post new threads for those. Appreciate your help!
Jul 9 '15 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Accessguest | last post by:
I've been given an Access DB for debugging. When running a query for a report the code stops with "Run time error 13 Type mismach". The code is stopping on the Else clause c =...
2
by: skundu | last post by:
Hi, I have just joined. I am getting a message when I am running a macro - run time error '13', type mismatch. when I am debuggung it it opens up my VBA code and shows this: Sub Updategraph()...
2
by: Wernerh | last post by:
VB6 - Please could anyone tell me why I am getting this error on the following code? VB6 Code Shell ("Explorer.exe App.Path & " \ "&" \ Report), vbMaximizedFocus Thanks Werner
4
by: JFKJr | last post by:
Hello everyone, the following code is working fine for the first time when I run it and giving "Run-time error '13': Type mismatch" at line #15 during the second time and so on.... The code is...
2
rhitam30111985
by: rhitam30111985 | last post by:
HI all , I am using Windows 2000 OS for out server . We use a VB tool to deploy all the COM applications. In that , this is a snippet of code that is failing : Option Explicit Dim...
1
by: muddasirmunir | last post by:
Please tell me what wrong in that code. I had many forms in MDI Child, which i want to adjust height and widht by the use of function. I had made the following function and put in in moudule at...
3
by: Drahy | last post by:
Hello I have difficulty in solving the run time error 13 type mismatch. I do not know how to solve it. If i write this code "JOR_No.Value = Right(List225.ItemData(icount), 4) + 1". The error will...
5
by: IbrahimL | last post by:
Hello Everyone, I have successfully created a login page for my Order Processing System. When I enter my Username and Password correctly it logs in successfully and moved onto my next form called...
6
by: julienmy5757 | last post by:
Hello, I am writing a code for a subform in datasheet view, but I have the error in the title. For set MyTable If you can help me, it is very important. Private Sub Form_Load() Dim...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.