script, module and function

mobile75

New member
Local time
Today, 16:47
Joined
Jul 25, 2013
Messages
8
I've create this simple script (file name test.vbs), I use it for scheduling a little job:

dim accessApp

set accessApp = createObject("Access.Application")

accessApp.OpenCurrentDataBase("D:\Files\Galileo\SF Mail.mdb")

accessApp.Run "MailOrdiniAgente"
accessApp.Quit
set accessApp = nothing

And I've created this Access module (saved into SFMail.mdb, module name MailOrdiniAgente )

Private Sub MailOrdiniAgente()
On Error GoTo Err_MailOrdiniAgente

Dim stDocName As String
Dim FileName, Check As String
Dim vMailA As String
Dim rs, ra As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("Tabella agenti", dbOpenDynaset)
If rs.EOF Then
GoTo Exit_MailOrdiniAgente
End If
rs.MoveFirst
Do Until rs.EOF
FileName = Replace(rs.Fields("CODICE"), " ", "")
Check = rs.Fields("INVIOMAIL")
vMailA = rs.Fields("MAIL")
If Check = "Vero" Then

DoCmd.RunMacro "Macro eliminazione filtro agente"

Set ra = CurrentDb.OpenRecordset("Tabella filtro agente", dbOpenDynaset)
ra.AddNew
ra.Fields("AGENTE") = FileName
ra.Update

DoCmd.RunMacro "Macro SapSF"

DoCmd.OutputTo acOutputReport, "Report agente ordini aperti", acFormatPDF, "C:\Temp\Agente" & FileName & ".pdf"

ra.Close

End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing

Exit_MailOrdiniAgente:
Exit Sub

Err_MailOrdiniAgente:
MsgBox Err.Description
Resume Exit_MailOrdiniAgente

End Sub

Problem running this script:
Windows Script Host... impossible find routine 'MailOrdiniAgente' error code 800A09D5

I'm not a great programmer, so probably I wrong something on creating the module or into the code of the same module that I've posted on top... I'm useing access 2007
Thanks a lot for help or advice me!
 
besides what Paul has suggested, something else that may cause a problem is that the module and the sub/function both have the same name ..
module name MailOrdiniAgente
Private Sub MailOrdiniAgente()
It may be better to have different names perhaps the module name could be:
mod_MailOrdiniAgente

David
 
Thanks to all, my dear friends, I've solved changeing from private to public and applying a new different name
 

Users who are viewing this thread

Back
Top Bottom