473,386 Members | 1,712 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,386 software developers and data experts.

Type Mismatch error after compact and repair

255 100+
Since I just use MS Access 2003 to compact and repair a corrupted database, more errors were shown from it that weren't existed before the corruption. There are 2 errors I'm currently having:

3421 Data type conversion error
The error highlights the following code
Expand|Select|Wrap|Line Numbers
  1.     fmtFrom = "cdate('" & Format(fromDate, "dd-mmm-yyyy") & "')"
  2.     fmtTo = "cdate('" & Format(toDate, "dd-mmm-yyyy") & "')"
  3.  
  4.     fmtDateRange = "cdate(format([date],'dd-mmm-yyyy'))>=" & _
  5.          fmtFrom & " And cdate(format([date],'dd-mmm-yyyy'))<= " & fmtTo
  6.  
  7.     WHERESQL = WHERESQL & " AND " & _
  8.         fmtDateRange
  9.  
  10. mydb.Execute ("UPDATE Attendance SET ManfHours = IIF(isNull(ManfHours),0,ManfHours) , " & _
  11.         " WhouseHours = IIF(isNull(WhouseHours),0,WhouseHours) , " & _
  12.         " [Other Hrs] = IIF(isNull([Other Hrs]),0,[Other Hrs]) " & _
  13.          WHERESQL)
WHERESQL is a string defined under [Option Explicit], it stores the date filter criteria with 2 input date variables.


3464 Data type mismatch in criteria expression
The error highlights this line of code
Expand|Select|Wrap|Line Numbers
  1. RptRS.Fields(rptFieldIndex) = QueryRS.Fields(queryFieldIndex)
RptRS and QueryRS is the recordset, and both sides are integers.

The errors are from 3 forms, the forms only have 2 date selection (From and To) and a preview button to create a report output. The database I'm using is a split database, where the corrupted one stores the tables. So is it still possible the problems locate in the database that stores the queries, forms and reports? Or what should I do with the database that stores the tables to fix the "type" errors.
Jun 29 '10 #1
2 1970
colintis
255 100+
I found the problem for type mismatch error, its actually the WHERESQL string is holding the SQL with VBA code. I put the quotes around to solve this issue...

Expand|Select|Wrap|Line Numbers
  1.  
  2.     fmtDateRange = "[Date] BETWEEN #" & _
  3.                     Format(fromDate, "mm/dd/yyyy") & "# And #" & _
  4.                     Format(toDate, "mm/dd/yyyy") & "#"
  5.  
  6.  
But I'm still having the "Data Type Conversion Error". I'm placing a bigger code range here for this error.

Expand|Select|Wrap|Line Numbers
  1. Do While Not QueryRS.EOF
  2.         With RptRS
  3.             .AddNew
  4.             !EmployeeNo = QueryRS!EmployeeNo
  5.             !EmpName = QueryRS!EmpName
  6.             !RosterCode = QueryRS!RosterCode
  7.             !Area = QueryRS!Area
  8.             !Shift = QueryRS!Shift
  9.             !Duties = QueryRS!Duties
  10.             !n = QueryRS!n
  11.             !s = QueryRS!s
  12.             !r = QueryRS!r
  13.  
  14.             Dim rptFieldIndex, queryFieldIndex As Integer
  15.             rptFieldIndex = StartField
  16.             queryFieldIndex = LastFixFieldsNo + 1
  17.             For i = LastFixFieldsNo + 1 To RptFieldCount - 1
  18.                 ' if not in the query
  19.                 If (i < StartField) Then
  20.                     .Fields(i) = "~"
  21.                 ElseIf (queryFieldIndex > QueryFieldCount - 1) Then
  22.                     .Fields(rptFieldIndex) = "~"
  23.                     rptFieldIndex = rptFieldIndex + 1
  24.                 Else
  25.                     .Fields(rptFieldIndex) = QueryRS.Fields(queryFieldIndex)
  26.                     rptFieldIndex = rptFieldIndex + 1
  27.                     queryFieldIndex = queryFieldIndex + 1
  28.                 End If
  29.             Next i
  30.  
  31.             .Update
  32.             QueryRS.MoveNext
  33.         End With
  34.     Loop
StartField is = LastFixFieldsNo + 1, the number 1 represents the start date is Monday, and + 2 for Tuesday and so on to Friday.

LastFixFieldsNo is a const integer
Jun 29 '10 #2
NeoPa
32,556 Expert Mod 16PB
See indented below for some tips.

In this case I suggest you get everything you pass to MyDB.Execute in line #10 and put it into a string variable. When you have this available print it to the Immediate Pane then execute it.

Note what occurs (any error messages) and then copy the contents of that variable (from the Immediate Pane) and paste it into a new post here (with full details of any error). With that we can get a better idea of what we're looking at.
One of the most popular (frequently occurring rather than best liked) problems we get is with SQL strings being manipulated in VBA code.

The reason this is so difficult is that all the work is being done at a level of redirection. What I mean by this is that the coder is never working directly with the SQL itself, but rather with code which in turn, is relied on to produce the SQL that they are envisaging is required. It's rather similar to the problems coders have historically had dealing with pointers.

Anyway, a technique I often suggest to coders struggling with this (at any level. This happens to experienced coders too.) is to use either the MsgBox() function, or Debug.Print into the Immediate Pane of the debugger window, to display the value of the SQL in the string before using it (That's assuming you're not good with debugging generally. Personally I would trace to the line, then display the value prior to allowing execution of the string - See Debugging in VBA). It's really much easier to appreciate what a SQL string is meant to do, and where there may be problems, when you can see it in its entirety, and in its true form, rather than as the code is about to create it.
Jun 29 '10 #3

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

Similar topics

4
by: leslie_tighe | last post by:
Hello, I have a method on a com+ object that is returning an array of objects. I know the array is popluated as calls to check the ubound and lbound show valid values. However, any calls to...
4
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...
3
by: Martin Lacoste | last post by:
Is there some issue with using too many left/right/mid/len functions in queries? Depending on the usage, they work fine, but... then there's here: SELECT Master_CAO.Incipit,...
6
by: shan | last post by:
What is the meaning for the error expression syntax and type mismatch error.I am using turbo c++.can anybody correct the errors in the folowing program. Following program is to find matrix...
1
by: jodyblau | last post by:
I am getting a type mismatch message under strange circumstances. Here's whats going on: 1. I have split the database into a front end and a back end. 2. I have compiled the project. 3. ...
4
by: sara | last post by:
I have an A2K database that has links to 3 of my other databases (external links) to run some reports. The coding in any of the 4 is pretty simple. Recently when we make a new .mde for the...
2
by: Rehan | last post by:
Hi there! Please help me out here. I am an inch away from completing my assignment. I am very new to VBA but i have very less time to be efficient at it. I am getting a type mismatch error...
5
by: kjworm | last post by:
Hello Everyone, I have been fighting with a type mismatch error for many hours today and I can't seem to find what the problem is. Hopefully it is more than a missing apostrophe! I have isolated...
7
by: Mike | last post by:
Type Mismatch error I recieve a type mismatch error on the following line of code which is based on a specific date. It does NOT break on all records only "some". The dates for the records...
5
by: Lara1 | last post by:
Hi, I'm a total beginner to VBA, so please bear with me if I seem a bit dense. What I'm Trying to Achieve I'm trying to write a procedure in Excel, which is supposed to - look at the pH...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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,...

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.