Error 2950 RunCode

J

Jake F

I'm trying to run a macro to run a code in my module, but get this error. I
changed the code to a different function and it ran it in this module so i
know it's something to do with my code either the titles or references or
something. I called the code from the macro using the ... button so i know
it's named right in the macro which leaves me to my code. Here it is,
hopefully you can see what I can't. Thanks.

Public Function MissedOpps()
On Error GoTo Err_MissedOpps

Dim Output As String
Dim Frm As String
Dim SendTo As String
Dim Subject As String
Dim Body As String

Output = "Missed Opps" & Format(Date, "yyyy_mm_dd")
Frm = [frmReportRu]
SendTo = Frm![Emailto]
Subject = Frm![Subject]
Body = Frm![Body]

'Output file
DoCmd.OutputTo acOutputQuery, "Missed Opps", ".xls", Output

'Send file
DoCmd.SendObject acSendQuery, "Missed Opps", ".xls", SendTo, , ,
Subject, Body, no

'Enter date into last run field on form
Forms![FrmReportRun]![Last Run] = Date

Exit_MissedOpps:
Exit Function
Err_MissedOpps:
MsgBox Err.Description
Resume Exit_MissedOpps:
End Function
 
M

mcescher

I'm trying to run a macro to run a code in my module, but get this error. I
changed the code to a different function and it ran it in this module so i
know it's something to do with my code either the titles or references or
something.  I called the code from the macro using the ... button so i know
it's named right in the macro which leaves me to my code.  Here it is,
hopefully you can see what I can't.  Thanks.

Public Function MissedOpps()
On Error GoTo Err_MissedOpps

  Dim Output As String
  Dim Frm As String
  Dim SendTo As String
  Dim Subject As String
  Dim Body As String

  Output = "Missed Opps" & Format(Date, "yyyy_mm_dd")
  Frm = [frmReportRu]
  SendTo = Frm![Emailto]
  Subject = Frm![Subject]
  Body = Frm![Body]

   'Output file
    DoCmd.OutputTo acOutputQuery, "Missed Opps", ".xls", Output

   'Send file
    DoCmd.SendObject acSendQuery, "Missed Opps", ".xls", SendTo, , ,
Subject, Body, no

   'Enter date into last run field on form
    Forms![FrmReportRun]![Last Run] = Date

Exit_MissedOpps:
  Exit Function
Err_MissedOpps:
  MsgBox Err.Description
  Resume Exit_MissedOpps:
End Function

I think your Frm variable needs to be declared as a form and then
initialized with the Set command

Dim Frm As Form
....
Set Frm = Forms!frmReportRu
SendTo = Frm!Emailto
....
Set Frm = Nothing
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top