For example, I’m trying to write:
Dim rec1 As Recordset
Set rec1 = CurrentDb.OpenRecordset("MySchedulewXdept1") ‘This query (MySchedulewXdept1) is filtered based on the date that I have on another open form.
I get a Run-time error '3061': Too few parameters. Expected 1.
My main objective is to create a chart that I can email to users with their schedule. Since they can make changes to their schedule anytime from now until 3 weeks from now, I need to know the date that they've selected from the form to know which schedule to create and send.
Here's the rest of my code if that helps. I'm using late binding because I was having issues with users with 2007 and 2010 runtime versions.
Public Sub SendMailSSSch()
Dim olapp As Object
Dim olmail As Object
Const olmailitem As Long = 0
'Schedule
Dim rec1 As Recordset
Dim aHead(1 To 3) As String
Dim aRow(1 To 3) As String
Dim aBody() As String
Dim lCnt As Long
'Create the header row - Schedule
aHead(1) = "Home?"
aHead(2) = "Interval Start"
aHead(3) = "My Schedule"
lCnt = 1
ReDim aBody(1 To lCnt)
aBody(lCnt) = "<HTML>******><table border='2'><tr><th>" & Join(aHead, "</th><th>") & "</th></tr>"
'Create each body row - Schedule
Set rec1 = CurrentDb.OpenRecordset("MySchedulewXdept1")
If Not (rec1.BOF And rec1.EOF) Then
Do While Not rec1.EOF
lCnt = lCnt + 1
ReDim Preserve aBody(1 To lCnt)
aRow(1) = rec1("FHome")
aRow(2) = rec1("IntervalStart")
aRow(3) = rec1("FinWhere")
aBody(lCnt) = "<tr><td>" & Join(aRow, "</td><td>") & "</td></tr>"
rec1.MoveNext
Loop
End If
aBody(lCnt) = aBody(lCnt) & "</table></body></html>"
'Fixed
Dim rec2 As Recordset
Dim bHead(1 To 2) As String
Dim bRow(1 To 2) As String
Dim bBody() As String
Dim lCnts As Long
'Create the header row - Fixed
bHead(1) = "Time"
bHead(2) = "Department"
lCnts = 1
ReDim bBody(1 To lCnts)
bBody(lCnts) = "<HTML>******><table border='2'><tr><th>" & Join(bHead, "</th><th>") & "</th></tr>"
'Create each body row - Fixed
Set rec2 = CurrentDb.OpenRecordset("MyDailyRestrict")
If Not (rec2.BOF And rec2.EOF) Then
Do While Not rec2.EOF
lCnts = lCnts + 1
ReDim Preserve bBody(1 To lCnts)
bRow(1) = rec2("IntervalStart")
bRow(2) = rec2("FinWhere")
bBody(lCnts) = "<tr><td>" & Join(bRow, "</td><td>") & "</td></tr>"
rec2.MoveNext
Loop
End If
bBody(lCnts) = bBody(lCnts) & "</table></body></html>"
Set olapp = CreateObject("outlook.application")
If olapp Is Nothing Then
MsgBox "Outlook is not open. Please open Outlook and try again."
Else
Set olmail = olapp.CreateItem(olmailitem)
With olmail
.To = "Amanda.Falvo@mcmaster.com" 'Forms!ssvacdayfrm!txtEmail
.Subject = "My Schedule for " & Forms![Self-Service]!TxtTab
.htmlBody = "Fixed Intervals:" & "<br>" & "Periods when you aren't able to change your schedule." & "<br>" & Join(bBody, vbNewLine) & "<br>" & "<br>" & Join(aBody, vbNewLine)
.Send
End With
End If
Set olapp = Nothing
Set olmail = Nothing
End Sub
Dim rec1 As Recordset
Set rec1 = CurrentDb.OpenRecordset("MySchedulewXdept1") ‘This query (MySchedulewXdept1) is filtered based on the date that I have on another open form.
I get a Run-time error '3061': Too few parameters. Expected 1.
My main objective is to create a chart that I can email to users with their schedule. Since they can make changes to their schedule anytime from now until 3 weeks from now, I need to know the date that they've selected from the form to know which schedule to create and send.
Here's the rest of my code if that helps. I'm using late binding because I was having issues with users with 2007 and 2010 runtime versions.
Public Sub SendMailSSSch()
Dim olapp As Object
Dim olmail As Object
Const olmailitem As Long = 0
'Schedule
Dim rec1 As Recordset
Dim aHead(1 To 3) As String
Dim aRow(1 To 3) As String
Dim aBody() As String
Dim lCnt As Long
'Create the header row - Schedule
aHead(1) = "Home?"
aHead(2) = "Interval Start"
aHead(3) = "My Schedule"
lCnt = 1
ReDim aBody(1 To lCnt)
aBody(lCnt) = "<HTML>******><table border='2'><tr><th>" & Join(aHead, "</th><th>") & "</th></tr>"
'Create each body row - Schedule
Set rec1 = CurrentDb.OpenRecordset("MySchedulewXdept1")
If Not (rec1.BOF And rec1.EOF) Then
Do While Not rec1.EOF
lCnt = lCnt + 1
ReDim Preserve aBody(1 To lCnt)
aRow(1) = rec1("FHome")
aRow(2) = rec1("IntervalStart")
aRow(3) = rec1("FinWhere")
aBody(lCnt) = "<tr><td>" & Join(aRow, "</td><td>") & "</td></tr>"
rec1.MoveNext
Loop
End If
aBody(lCnt) = aBody(lCnt) & "</table></body></html>"
'Fixed
Dim rec2 As Recordset
Dim bHead(1 To 2) As String
Dim bRow(1 To 2) As String
Dim bBody() As String
Dim lCnts As Long
'Create the header row - Fixed
bHead(1) = "Time"
bHead(2) = "Department"
lCnts = 1
ReDim bBody(1 To lCnts)
bBody(lCnts) = "<HTML>******><table border='2'><tr><th>" & Join(bHead, "</th><th>") & "</th></tr>"
'Create each body row - Fixed
Set rec2 = CurrentDb.OpenRecordset("MyDailyRestrict")
If Not (rec2.BOF And rec2.EOF) Then
Do While Not rec2.EOF
lCnts = lCnts + 1
ReDim Preserve bBody(1 To lCnts)
bRow(1) = rec2("IntervalStart")
bRow(2) = rec2("FinWhere")
bBody(lCnts) = "<tr><td>" & Join(bRow, "</td><td>") & "</td></tr>"
rec2.MoveNext
Loop
End If
bBody(lCnts) = bBody(lCnts) & "</table></body></html>"
Set olapp = CreateObject("outlook.application")
If olapp Is Nothing Then
MsgBox "Outlook is not open. Please open Outlook and try again."
Else
Set olmail = olapp.CreateItem(olmailitem)
With olmail
.To = "Amanda.Falvo@mcmaster.com" 'Forms!ssvacdayfrm!txtEmail
.Subject = "My Schedule for " & Forms![Self-Service]!TxtTab
.htmlBody = "Fixed Intervals:" & "<br>" & "Periods when you aren't able to change your schedule." & "<br>" & Join(bBody, vbNewLine) & "<br>" & "<br>" & Join(aBody, vbNewLine)
.Send
End With
End If
Set olapp = Nothing
Set olmail = Nothing
End Sub