Hello,
I'm kind of new to VBA and Access, so please forgive me if I'm doing stuff all wrong:
I have the following code wich gives me a Error 13 Type Mismatch: -
-
Dim db As Database, rs As Recordset
-
Dim strSQL As String
-
Dim ToDate, TillDate As String
-
-
ToDate = "" & GP_DateFrom.Value & ""
-
TillDate = "" & GP_DateUntil.Value & ""
-
-
-
strSQL = "SELECT * FROM SBB_General_Purpose WHERE Datum BETWEEN " _
-
& ToDate & " AND " & TillDate & ";"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(strSQL)
-
-
' if it gets here then the code to open the recordset has worked
-
lstDisplay.Requery
-
rs.Close
-
db.Close
-
-
-
It gives the error on the Set rs=db.OpenRecordset(strSQL) line.
Anyone any ideas on how to resolve this?
Thanks in advance,
Jasper
10 2998 datum is a date type field, right? If so, you need to place # delimiters around the date values in the SQL string. See the Access article which explains the issue.
Also, I believe SQL requires dates to be in U.S. format (m/d/y), which may or may not be a problem. I'd suggest you halt execution after the line that sets strSQL, and display the value in the string. Post it here if you like, and we can see how it looks..
Yes, you are right, it is a date field. However: I tried using # around the dates, this did not work. Also, I get the same error when I don't use any WHERE-statement at all: -
' Now without the WHERE
-
-
strSQL = "SELECT * FROM SBB_General_Purpose"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(strSQL)
-
-
Gives me the same error. Strange, ain't it?
Jasper
Yes, you are right, it is a date field. However: I tried using # around the dates, this did not work. Also, I get the same error when I don't use any WHERE-statement at all: -
' Now without the WHERE
-
-
strSQL = "SELECT * FROM SBB_General_Purpose"
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(strSQL)
-
-
Gives me the same error. Strange, ain't it?
Jasper
Hi ,
The basic reason for this error is that the SQL syntax is incorrect. But from your query it does not seem so. Are you able to execute the query sucessfully on the query analyser.
good luck
-ansuman sahu
Hi ,
The basic reason for this error is that the SQL syntax is incorrect. But from your query it does not seem so. Are you able to execute the query sucessfully on the query analyser.
good luck
-ansuman sahu
I'll check the query analyser, i'll post the result in a moment.
Back ;)
I can use this query without any probs in the Access Query analyzer:
SELECT * FROM SBB_General_Purpose WHERE Datum BETWEEN #01-01-1900# AND #01-01-2100#
It also works when I lose the WHERE.... statement.
Gives me 2 results, which is OK since I only have 2 records in the DB at the moment (I'm still developing it).
So I guess my SQL statement is OK. I'm kinda stuck here. Any suggestions?
Perhaps some sort of problem with your connection string? I'm pretty vague on that whole area.
Just found it. I declared rs as a recordset, it should be a DAO.Recordset. Works pretty nice now :)
For the ones interested, here is the complete code. It does a query based on date-input on a form, then exports this data to Excel: -
Private Sub cmdOk_Click()
-
On Error GoTo Err_cmdOk_Click
-
-
Dim db As Database, rs As DAO.Recordset
-
Dim strSQL As String
-
Dim ToDate, TillDate As String
-
Dim i As Integer
-
Dim iNumCols As Integer
-
-
'Start a new workbook in Excel
-
Dim oApp As New Excel.Application
-
Dim oBook As Excel.Workbook
-
Dim oSheet As Excel.Worksheet
-
-
' Start date was empty, assume user wants all history so set it to 1-1-1990
-
If GP_DateFrom.Value = "" Then
-
GP_DateFrom = "01-01-1900"
-
End If
-
-
If GP_DateFrom = "01-01-1900" Then
-
Answer = MsgBox("Are you sure you want to see all data from 01-01-1900 till " & GP_DateUntil.Value & "?", vbYesNo, "Are you sure?")
-
If Answer = vbNo Then Exit Sub
-
End If
-
-
' SQL uses mm-dd-yyyy, our users give us dd-mm-yyyy, so let's change that
-
' also add a # in front and at the end to make MS happy
-
ToDate = "#" & Mid(GP_DateFrom.Value, 4, 2) & "-" & Left(GP_DateFrom.Value, 2) & _
-
"-" & Right(GP_DateFrom.Value, 4) & "#"
-
TillDate = "#" & Mid(GP_DateUntil.Value, 4, 2) & "-" & Left(GP_DateUntil.Value, 2) & _
-
"-" & Right(GP_DateUntil.Value, 4) & "#"
-
-
' This should be the final SQL cmd
-
strSQL = "SELECT * FROM SBB_General_Purpose WHERE Datum BETWEEN " _
-
& ToDate & " AND " & TillDate & ";"
-
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset(strSQL)
-
-
If Not rs.BOF And Not rs.EOF Then ' it has records
-
-
iNumCols = rs.Fields.Count
-
-
Set oBook = oApp.Workbooks.Add
-
Set oSheet = oBook.Worksheets(1)
-
-
For i = 1 To iNumCols
-
oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name
-
Next
-
-
' Add the data starting at cell A2
-
oSheet.Range("A2").CopyFromRecordset rs
-
-
'Format the header row as bold and autofit the columns
-
With oSheet.Range("a1").Resize(1, iNumCols)
-
.Font.Bold = True
-
.EntireColumn.AutoFit
-
End With
-
-
oApp.Visible = True
-
oApp.UserControl = True
-
Else
-
-
MsgBox "No data in query!", vbOKOnly, "No data"
-
-
End If
-
-
' Close the DB
-
rs.Close
-
db.Close
-
-
Exit Sub
-
-
Err_cmdOk_Click:
-
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error " & Err.Number
-
Resume Next
-
-
End Sub
-
-
Hope this might be usefull for some, and thanks for any input you gave me guys, I appreciate it :)
Jasper
Glad to see you got it. :)
And thanks for posting the working code. If I can find time, I might edit it a bit (for consistency with other entries) and add it to the "how-to samples" in the VB Articles area. We often get questions about things like importing to Excel, and database-related ones. As a sample, this will hit two areas in one go.
hI.. i am getting the same error.
The thing is ive used this code else where and it didn't give me problems but in this particular case where I have it it does.
Function GetDateFilter(dtDate As Date) As String
GetDateFilter = "#" & Format(dtDate, "DD/MM/YYYY hh:mm:ss AM/PM") & "#"
End Function
The above function is called in the following code....
If IsDate(Me.Date_Project_Modified) Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "Query2.Date_Project_Modified >= " & GetDateFilter(Me.Date_Project_Modified)
ElseIf Nz(Me.Date_Project_Modified) <> "" Then
strError = cInvalidDateError
End If
Any ideas?
Which line produces the error?
Oh! And what version of VB are you using?
And what does Me refer to?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stephen Briley |
last post by:
For some reason, my posts are scrubbed as attachments.
Lets hope that sending from the yahoo account works.
I'm new to Python and I'm trying to do some database
work with MS Access, but I can't...
|
by: Steve Briley |
last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error". Here's an example table that I'm working with...
...
|
by: DrewM |
last post by:
This is a strange request - but I'm trying to generate a Type Mismatch
error. It's for an example in some documentation.
I was looking for something that would error (like a mathematical equation...
|
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...
|
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...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much...
|
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...
|
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...
|
by: Prasad |
last post by:
HI,
I am a beginner in VC++..
I am trying to write a Win32 console application in visual studio..
I am using following header files..
#include <STRING>
using namespace std;
#include...
|
by: sara |
last post by:
Hi -
I have code (below) that ran as recently as Monday.
We decided to change the location for the output reports, and now the
code errors (13 Type Mismatch) on the query.
The query runs fine...
|
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: 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: 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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |