An Expression You Entered Is the Wrong Data Type for one of the Arguments

bluedemon186

Registered User.
Local time
Today, 15:18
Joined
Dec 7, 2011
Messages
20
Hello,

I am using the following code to open another form to a specific record and email a pdf of that particular record. It works in one of the form and gives an error in another. Can someone please take a look at the code and see why it is giving me that error. From what I understand it might be the Do.Cmd.Sendobject line. To add further it only gives me that error when I try to use the button for old records. It works just fine with the newer records.

Code:
Private Sub Command284_Click()
On Error GoTo Command284_Click_Err
      DoCmd.RunCommand acCmdSaveRecord
 
    Dim stDocName As String
    Dim stLinkCriteria As String
 
 
    stDocName = "SampleNotification"
 
    stLinkCriteria = "[Sample_Nbr]=" & "'" & Me![Sample_Nbr] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.SelectObject acForm, stDocName, True
    Forms("SampleNotification").Printer.Orientation = acPRORLandscape
 
    DoCmd.SendObject acForm, "SampleNotification", "PDFFormat(*.pdf)", Me.ClientEmail, "", "", "Sample Notification", "", True, ""
 
Command284_Click_Exit:
    Exit Sub
Command284_Click_Err:
    MsgBox Error$
    Resume Command284_Click_Exit
End Sub
 
Last edited:
Can we start by commenting out the error handler. So change this line

On Error GoTo Command284_Click_Err

to this

' On Error GoTo Command284_Click_Err

i.e. prefix it with a single quote. Once you've done that re-rerun the code, when it errors hit Debug and tell us what line it highlights and what the error message is.
 
This is the lient hat was highighted.

Code:
DoCmd.SendObject acForm, "SampleNotification", "PDFFormat(*.pdf)", Me.ClientEmail, "", "", "Sample Notification", "", True, ""

However, it didn't give me any error when I tried it for the same records before doing what you asked me. For some reason it gives me an error on some days and works just fine on other. This is really weird because I did not change a thing on it.
 
Well, it will be worthwhile telling me what error message pops up sometimes when it's run.
 
An Expression You Entered Is the Wrong Data Type for one of the Arguments. I put the error in the title of the thread.
 
First off, three things.

1. Your code needs to be changed to remove the comma and "" at the end.
2. Also, the output format is actually acFormatPDF
3. and the cc, bcc, and message need to have NOTHING in them, just the commas. When you have an optional parameter you do not include anything but the comma as the placeholder if you enter it the way you have.

DoCmd.SendObject acForm, "SampleNotification", acFormatPDF, Me.ClientEmail, , , "Sample Notification", , True
 

Users who are viewing this thread

Back
Top Bottom