I have an Events table that records events with the fields:
[ID], [ContactID], [Event](Text), and [EventDate] it is used as a note pad to record calls made to and from contacts and other occurrences.
I also have a MailShot selection form for setting up MS Word mailings to groups of contacts, normally between two dates.
The query on the MailShot form selects Name and address etc. from the 'Contacts' table according to the settings on the MailShot form and contains the field [ContactID] and all relevant data for the mailshot.
Every thing works fine.
Now I want to enter a new text event (“Last Mailshot Sent”) in the [Event] field and the date in the [EventDate] field of the 'Events' Table for each contact in the MailShot query to keep a record of the last mailing date for each contact.
This will happen automatically when a MsgBox asking if you really want to create the MailShot is answered in the affirmative.
The code below seems to be right but throws an Error 'Data Mismatch in criteria' at the line marked <<<<
the code includes the QueryDef bit because it threw errors about Parameters being required.
Your Help would be much appreciated.
Andy.
[ID], [ContactID], [Event](Text), and [EventDate] it is used as a note pad to record calls made to and from contacts and other occurrences.
I also have a MailShot selection form for setting up MS Word mailings to groups of contacts, normally between two dates.
The query on the MailShot form selects Name and address etc. from the 'Contacts' table according to the settings on the MailShot form and contains the field [ContactID] and all relevant data for the mailshot.
Every thing works fine.
Now I want to enter a new text event (“Last Mailshot Sent”) in the [Event] field and the date in the [EventDate] field of the 'Events' Table for each contact in the MailShot query to keep a record of the last mailing date for each contact.
This will happen automatically when a MsgBox asking if you really want to create the MailShot is answered in the affirmative.
The code below seems to be right but throws an Error 'Data Mismatch in criteria' at the line marked <<<<
the code includes the QueryDef bit because it threw errors about Parameters being required.
Code:
Dim StrSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim ShtDate
Dim LngDate
ShtDate = Format$(Date, "\#mm\/dd\/yyyy\#")
LngDate = Format$(Date, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
Set db = CurrentDb
Set qdf = db.QueryDefs("MailShotQuery")
qdf(0) = CBool([Forms]![MailshotForm]![Check0])
qdf(1) = CStr([Forms]![MailshotForm]![Combo2])
qdf(2) = CDate([Forms]![MailshotForm]![Start])
qdf(3) = CDate([Forms]![MailshotForm]![End])
Set rs = qdf.OpenRecordset(dbOpenDynaset) '<<< It breaks here <<<<<
rs.MoveFirst
Do While Not rs.EOF ' Start of loop, First Row
StrSQL = "INSERT INTO EventsTable (LeadID,Event,EventDate) " & _
"VALUES (" & rs![Lead No] & ",'Mailshot Sent '," & ShtDate & ")"
DoCmd.RunSQL StrSQL
rs.MoveNext ' Next Row
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
Andy.
Comment