getting Type MisMatch error on app.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am getting a Type MisMatch error: what I am trying to do is manualy add records of data that I fill out on a form. The compile does not show anything wrong, but when I close the database and open it again, and try to run the action. I get that error on type mismatch, the data I am trying to pass right now is the "date" but I don't know what to look for on this error.
 
Make sure that you surround the value in pound signs - for
example - #11/12/2003#
-----Original Message-----
I am getting a Type MisMatch error: what I am trying to
do is manualy add records of data that I fill out on a
form. The compile does not show anything wrong, but when I
close the database and open it again, and try to run the
action. I get that error on type mismatch, the data I am
trying to pass right now is the "date" but I don't know
what to look for on this error.
 
Also, in VBA dates are always mm/dd/yyyy (as opposed to dd/mm/yyyy), so:

12th August 2003 = #08/12/2003#

--
Michael Hopwood (Phobos)


Andrew said:
I am getting a Type MisMatch error: what I am trying to do is manualy add
records of data that I fill out on a form. The compile does not show
anything wrong, but when I close the database and open it again, and try to
run the action. I get that error on type mismatch, the data I am trying to
pass right now is the "date" but I don't know what to look for on this
error.
 
this is my code, but if I use date, numbers, or currency I will get the same error

Private Sub Create_invoices_Click(
On Error GoTo Err_Create_invoices_Clic

Dim dbsSP As Databas
Dim pts As DAO.Recordse
Dim dtDate As Dat


Set dbsSP = CurrentDb(
Set pts = dbsSP.OpenRecordset("Payments", dbOpenDynaset

'get the information that is neede
dtDate = Me![StartDate

'prodeed only if the user actually intered somthin
If dtDate <> "" The

'calls the funchion that adds the recor
addRec pts, dtDat

'shows the newly added data
With pt
Debug.Print "new record added

End Wit
Els
Debug.Print
"you must input a string for monthly payment and payment ID
End I

pts.Clos
dbsSP.Clos

Exit_Create_invoices_Click
Exit Su

Err_Create_invoices_Click
MsgBox Err.Descriptio
Resume Exit_Create_invoices_Clic

End Su

Function addRec(rstTemp As Recordset, dt As Date

With rstTem
.AddNe
!StartingDate = d
.Updat
.Bookmark = .LastModifie
End Wit

End Function
 
I tried and did not work, I am not shure about that but this is my code, and I get that error on if I put it to a long, currency, or interger

Private Sub Create_invoices_Click(
On Error GoTo Err_Create_invoices_Clic

Dim dbsSP As Databas
Dim pts As DAO.Recordse
Dim dtDate As Dat


Set dbsSP = CurrentDb(
Set pts = dbsSP.OpenRecordset("Payments", dbOpenDynaset

'get the information that is neede
dtDate = Me![StartDate

'prodeed only if the user actually intered somthin
If dtDate <> "" The

'calls the funchion that adds the recor
addRec pts, dtDat

'shows the newly added data
With pt
Debug.Print "new record added

End Wit
Els
Debug.Print
"you must input a string for monthly payment and payment ID
End I

pts.Clos
dbsSP.Clos

Exit_Create_invoices_Click
Exit Su

Err_Create_invoices_Click
MsgBox Err.Descriptio
Resume Exit_Create_invoices_Clic

End Su

Function addRec(rstTemp As Recordset, dt As Date

With rstTem
.AddNe
!StartingDate = d
.Updat
.Bookmark = .LastModifie
End Wit

End Function
 
Try replacing this:

If dtDate <> "" Then

with this:

If dtDate <> "" And IsDate(dtDate) Then

dtDate = "#" & dtDate & "#"
 
I did what you said, and I still get that error, I made shure that all the dates were exact the same on the talbles forms and soforth..
 
andrew said:
this is my code, but if I use date, numbers, or currency I will get
the same error:

Private Sub Create_invoices_Click()
On Error GoTo Err_Create_invoices_Click

Dim dbsSP As Database
Dim pts As DAO.Recordset
Dim dtDate As Date


Set dbsSP = CurrentDb()
Set pts = dbsSP.OpenRecordset("Payments", dbOpenDynaset)

'get the information that is needed
dtDate = Me![StartDate]

'prodeed only if the user actually intered somthing
If dtDate <> "" Then

'calls the funchion that adds the record
addRec pts, dtDate

'shows the newly added data.
With pts
Debug.Print "new record added"

End With
Else
Debug.Print _
"you must input a string for monthly payment and
payment ID" End If

pts.Close
dbsSP.Close

Exit_Create_invoices_Click:
Exit Sub

Err_Create_invoices_Click:
MsgBox Err.Description
Resume Exit_Create_invoices_Click

End Sub

Function addRec(rstTemp As Recordset, dt As Date)

With rstTemp
.AddNew
!StartingDate = dt
.Update
.Bookmark = .LastModified
End With

End Function

I suspect your problem is here:
Function addRec(rstTemp As Recordset, dt As Date)

Change that to:

Function addRec(rstTemp As DAO.Recordset, dt As Date)
 
Also, in VBA dates are always mm/dd/yyyy (as opposed to dd/mm/yyyy), so:

12th August 2003 = #08/12/2003#

Not in this part of the world it isn't. VBA default coercion from date to
text uses the Regional settings. Do not get it confused with Jet date
literals, which do have to be in a specified format regardless of the
Control Panel.

The upshot is *always* to use a Format() expression when converting dates
to text, and *always* use DateSerial() when converting the other way.

B Wishes


Tim F
 
Back
Top