0

I have a macro that runs a series of steps and outputs a report in MS Acces.s I want this report to be named using a variable from my form and stored in a particular file.

I have written VB code to do the same.

It runs perfectly well when i run the code, but from the macro it doesn't work!

Private Sub FileLocator()
If [Forms]![Date Form].[Frame37] = 1 Then
MsgBox ("Working")
x = [Forms]![Date Form].List29
Else
x = [Forms]![Date Form].List25
End If

DoCmd.OutputTo acOutputReport, "41_Webtime less than 40 hours chart", "PDFFormat(*.pdf)", "C:\" & x & "\" & x & ".pdf", True, "", , acExportQualityPrint

End Sub

From my macro i call Forms![Date Form]!FileLocator in RunCode

R3uK
  • 14,417
  • 7
  • 43
  • 77
Vivek Adi
  • 1
  • 3
  • possible duplicate of [MS Access RunCode Macro cannot find my procedure](http://stackoverflow.com/questions/17244980/ms-access-runcode-macro-cannot-find-my-procedure) – Gord Thompson Mar 02 '14 at 15:08
  • Nope! Changing it to function didn't work either. Doesn't show any error. But just doesnt run the function or sub – Vivek Adi Mar 02 '14 at 15:23
  • 1
    The function needs to be in a "regular" VBA Module, not in the Class Module for a specific form. In Access do `Create > Module` and then move the function into there as a `Public Function`. – Gord Thompson Mar 02 '14 at 15:27
  • Tried it doesn't work :( no error again. Just refuses to pick the function. It is in a separate module as well as under my form class object. How do i call the module function? I'm currently using Forms![Date Form]!FileLocator in RunCode – Vivek Adi Mar 03 '14 at 17:21

1 Answers1

1

Just had this issue myself, turns out you cannot have the module name the same as the function name.

Hope that is your issue as well.

user2864429
  • 63
  • 10