
Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
Indeed, it was interesting reading. Thanks. Still stuck though. Here is the
code and below I'll tell you what I tried:
Private Sub cmdBuildSchedule_Click()
Dim datThis As Date
Dim lngActID As Long
Dim lngLocID As Long
Dim varNotes As Variant
Dim strSQL As String
Dim db As DAO.Database
Dim intDOW As Integer 'day of week
Dim intDIM As Integer 'Day in month
If Me.grpRepeats = 2 Then
If Not CheckDates() Then
Exit Sub
End If
End If
If Not CheckTimes() Then
Exit Sub
End If
If IsNull(Me.cboActID) Then
MsgBox "You must select an Activity.", vbOKOnly + vbInformation,
"Enter Activity"
Me.cboActID.SetFocus
Me.cboActID.Dropdown
Exit Sub
End If
If IsNull(Me.cboLocID) Then
MsgBox "You must select a Location.", vbOKOnly + vbInformation,
"Enter Location"
Me.cboLocID.SetFocus
Me.cboLocID.Dropdown
Exit Sub
End If
'strTitle = Me.txtTitle
varNotes = Me.txtNotes
lngLocID = Me.cboLocID
lngActID = Me.cboActID
Set db = CurrentDb
If Me.grpRepeats = 2 Then 'need to loop through dates
For datThis = Me.txtStartDate To Me.txtEndDate
intDIM = GetDIM(datThis)
intDOW = Weekday(datThis)
If Me("chkDay" & intDIM & intDOW) = True Or _
Me("chkDay0" & intDOW) = True Then
strSQL = "INSERT INTO tblTempSchedDates (" & _
"tscDate, tscActID, tscLocID, " & _
"tscStartTime, tscEndTime, tscNotes ) " & _
"Values(#" & datThis & "#," & lngActID & ", " & _
lngLocID & ", #" & Me.txtStartTime & "#, #" & _
Me.txtEndTime & "#," & _
IIf(IsNull(varNotes), "Null", """" & varNotes & """") &
")"
db.Execute strSQL, dbFailOnError
End If
Next
Else 'dates are there, just add the title, notes, times, location,
Activity
strSQL = "Update tblTempSchedDates Set tscActID = " & lngActID & _
", tscLocID = " & lngLocID & ", tscStartTime =#" &
Me.txtStartTime & _
"#, tscEndTime = #" & Me.txtEndTime & "#"
If Len(varNotes & "") > 0 Then
strSQL = strSQL & ", tscNotes = " & IIf(IsNull(varNotes), Null,
"""" & varNotes & """")
End If
db.Execute strSQL, dbFailOnError
End If
Me.sfrmTempScheduleEdit.Requery
MsgBox "Temporary schedule built. " & _
"You can now edit the schedule and " & _
"append to the permanent schedule.", vbOKOnly + vbInformation, "Temp
schedule complete"
End Sub
OK. Since the date is taken from datThis, I tried:
For datThis = Format(Me.txtStartDate, "mm\/dd\/yyyy") To
Format(Me.txtEndDate, "mm\/dd\/yyyy")
That didn't work so in the strSQL I tried:
strSQL = "INSERT INTO tblTempSchedDates (" & _
"tscDate, tscActID, tscLocID, " & _
"tscStartTime, tscEndTime, tscNotes ) " & _
"Values(#" & Format(datThis, "mm\/dd\/yyyy") & "#," &
lngActID & ", " & _
lngLocID & ", #" & Me.txtStartTime & "#, #" & _
Me.txtEndTime & "#," & _
Unfortunately, that didn't work either. I wondered if the wrapping function
would be the best way to go, but had even less ideas on how or where to put
that. The form controls are unbound. I set the formats in the date fields to
'Short Date'
Thanks again
Ana
> What's the code you're using to generate strSQL?
>
[quoted text clipped - 76 lines]
> >> >
> >> > Thanks for insights on these two Qs.
Douglas J. Steele - 27 Nov 2006 22:29 GMT
Try:
For datThis = CDate(Me.txtStartDate) To CDate(Me.txtEndDate)
Definitely keep the format in the assignment to strSQL.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
> Indeed, it was interesting reading. Thanks. Still stuck though. Here is
> the
[quoted text clipped - 202 lines]
>> >> >
>> >> > Thanks for insights on these two Qs.
AnaP - 28 Nov 2006 23:37 GMT
That worked! The date was being formatted in the American way, but I was
still getting the same error message so using the info given to me thus far I
added:
Format(me.txtStartTime, "hh:nn") to all the code referring to the time and
it worked!! Now I have the demo working I can work on the adaptation. More
challenges ahead, no doubt! Thanks so much.
Ana
> Try:
>
[quoted text clipped - 208 lines]
> >> >> >
> >> >> > Thanks for insights on these two Qs.