Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expression entered is the wrong data type for one of my arguments

Status
Not open for further replies.

MISCurls

MIS
Dec 4, 2006
8
US
Good Morning all you brillant programmers out there! I would appreciate another pair of eyes on this Sub. The process emails a report to a list of email address from a table. The report iterates through the set in the table however when it finishes before closing out to the main Form it errors out with "wrong data type". The watch line is (DoCmd.SendObject acSendReport, "R Nursing Shift Report Data from Input", acFormatRTF, rs!email, , , "Nursing Shift Report", "Nursing Shift Report", False). Strange thing is it works flawlessly in a form from an earlier iteration of my same application.
Thank you for your time.

Private Sub cmdEmail_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "Q Form Info from F Run Report", acViewNormal
DoCmd.OpenReport "R Nursing Shift Report Data from Input", acViewPreview, "", "", acNormal
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSave
DoCmd.Maximize
DoCmd.SetWarnings False
'Setup for email table iteration
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim strSQL As String
'Declare Report to be used for email
Dim stRpt As String
stRpt = "R Nursing Shift Report Data from Input"
'Iterate through all email addresses within the tblemail table to send the Nursing Shift Report
strSQL = "Select * from tblEmail"
rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
rs.MoveFirst
Do While Not rs.EOF
DoCmd.SendObject acSendReport, "R Nursing Shift Report Data from Input", acFormatRTF, rs!email, , , "Nursing Shift Report", "Nursing Shift Report", False
DoCmd.SetWarnings False
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
DoCmd.Close acReport, "R Nursing Shift Report Data from Input"
DoCmd.Close acQuery, "Q Form Info from F Run Report"
DoCmd.Close acForm, "F Run Report"
DoCmd.OpenForm "Main", acNormal, "", "", , acNormal
DoCmd.Maximize
End Sub
 
When I pasted your watch line into my text editor, the commas in "email, , , "Nursing Shift Report"" came over as having spaces betwen them. Just a shot in the dark, but try removing the spaces. Don't think you need a comma after EditMessage:=False for the TemplateFile placeholder, but you could try that, too.
Good Luck!

It's always darkest before dawn. So if you're going to steal your
neighbor's newspaper, that's the time to do it.
 
Object names that include spaces should be enclosed with square brackets.

"R Nursing Shift Report Data from Input"
"[R Nursing Shift Report Data from Input]"


This is true for ALL object names -- forms, queries, fields, etc.


Randy
 
When I tired the brackets Access could not find the report. however, there must have been an extra space as genomon was saying because I retyped the whole sendObject expression and sent it. No errors! Thank you very much to everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top