Type mismatch

Russyfoot

Registered User.
Local time
Today, 12:28
Joined
Aug 6, 2004
Messages
16
Hi. I'm trying to add several records, 7 days apart between two dates.
This is my first attempt at coding and after lots of reading and poring over various fora I've come up with the following code which I'm using in a simple test prior to adding to my existing DB.

My problem is that the highlighted line gives a type mismatch error. I've assigned the variable 'adddate' as Date and the field 'fromdate' is formatted as short date. I'm confused.


Private Sub cmbadd_Click()
On Error GoTo Err_cmbadd_Click
Dim rs As Recordset
Dim adddate As Date
Set rs = CurrentDb.OpenRecordset("tbltest1")
adddate = fromdate
Do While adddate <= endDate
rs.AddNew
rs!bookingdate = adddate
rs!txtstart = txtstart
rs!txtend = txtend
adddate = DateAdd(D, 7, adddate + 1)
Loop

Exit_cmbadd_Click:
Exit Sub

Err_cmbadd_Click:
MsgBox Err.Description
Resume Exit_cmbadd_Click

End Sub
_________________
Until I get past this I can't see if my code is working.

Any help will be appreciated.
 
Yes it is. Sorry should have made that clear.
 
I've tried that previously with the same result.

Just tried it again in case I'd done something really silly but again..same result.
 
As I said earlier, I'm confused. I put in some message boxes to step through the code and have found I was barking up the wrong tree completely ! it seems the type mismatch relates to he line

Set rs = CurrentDb.OpenRecordset("tbltest1").

Think I need to do a bit more research.
 
You can also use breakpoints to step through your code and find errors...

kh
 
Bear in mind that anything Formatted is a String representation.

Also, another reason for a Type mismatch is your implcit use of Recordset.

You are using DAO code but, in all likelihood, have only an ADO reference set.
 
Wow SJ.
I was off exploring your thread re DAO & ADO differences as I had a feeling this maybe where my problem was. I have got the DAO reference selected bu the ADO was above it in the reference list. Swapped them round & now it works.
(Well got a problem with the loop..but I'm getting there.)

Came back to report my update & there's a post from you SJ!!
(btw the link to microsoft on your DAO/ADO thread is no longer there.)

Thanks to you and Ken Higg for responding. if I need any more help will start a new thread.
 
Russyfoot said:
(btw the link to microsoft on your DAO/ADO thread is no longer there.)

Thanks. I'll see if I can restore it when I get home.

Rather than just move DAO above ADO in the reference list, you'll find it better to change the code a little:

ie..

Dim rs As DAO.Recordset
 

Users who are viewing this thread

Back
Top Bottom