Run a module from a button on a form

  • Thread starter Thread starter Steve in S.F.
  • Start date Start date
S

Steve in S.F.

I have a question that’s pretty basic, I’m sure, but I’m a bit of a novice in
the programming aspects of Access.

I have a database that I help administer, parts of which I developed and
parts of which were done by others. It contains a module written by someone
else that’s named “exportInvoiceLinesâ€.

To give a flavor for it, here the beginning section:

Public Sub exportInvoices()
Dim strBlanks
Dim invoiceLines As DAO.Recordset
Dim oFSO
Dim oTextFile
Dim orderTotal
Dim prevOrderID, prevCustID, prevOrderDate, prevContact
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.createtextFile("C:\Users\SMS\Desktop\invoices.txt")
Set invoiceLines = CurrentDb.OpenRecordset("select * from [tblBilling query]
order by orderID, custID")
strBlanks = " "
prevOrderID = invoiceLines!orderID
prevCustID = invoiceLines!custID
prevOrderDate = invoiceLines!orderDate
prevContact = invoiceLines!Contact
orderTotal = 0#
Do Until invoiceLines.EOF

If I open the module and click on “Runâ€, “Run Sub/UserForm†the module runs
and produces a text file we need.

I would like this module to run when a button on a form is pressed by the
user, but I don’t know what commands to put in the “On Click†Event Procedure
of the button to make this happen.

Can someone clue me in here?

Thanks,
Steve
 
I have a question thatÿs pretty basic, Iÿm sure, but Iÿm a bit of a novice in
the programming aspects of Access.

I have a database that I help administer, parts of which I developed and
parts of which were done by others. It contains a module written by someone
else thatÿs named ´exportInvoiceLines¡.

To give a flavor for it, here the beginning section:

Public Sub exportInvoices()
Dim strBlanks
Dim invoiceLines As DAO.Recordset
Dim oFSO
Dim oTextFile
Dim orderTotal
Dim prevOrderID, prevCustID, prevOrderDate, prevContact
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.createtextFile("C:\Users\SMS\Desktop\invoices.txt")
Set invoiceLines = CurrentDb.OpenRecordset("select * from [tblBilling query]
order by orderID, custID")
strBlanks = " "
prevOrderID = invoiceLines!orderID
prevCustID = invoiceLines!custID
prevOrderDate = invoiceLines!orderDate
prevContact = invoiceLines!Contact
orderTotal = 0#
Do Until invoiceLines.EOF

If I open the module and click on ´Run¡, ´Run Sub/UserForm¡ the module runs
and produces a text file we need.

I would like this module to run when a button on a form is pressed by the
user, but I donÿt know what commands to put in the ´On Click¡ Event Procedure
of the button to make this happen.

Can someone clue me in here?

Thanks,
Steve

Code the command button click event:

exportInvoices
 
Thanks so much for your help! That was pretty simple :)

fredg said:
I have a question that’s pretty basic, I’m sure, but I’m a bit of a novice in
the programming aspects of Access.

I have a database that I help administer, parts of which I developed and
parts of which were done by others. It contains a module written by someone
else that’s named “exportInvoiceLinesâ€.

To give a flavor for it, here the beginning section:

Public Sub exportInvoices()
Dim strBlanks
Dim invoiceLines As DAO.Recordset
Dim oFSO
Dim oTextFile
Dim orderTotal
Dim prevOrderID, prevCustID, prevOrderDate, prevContact
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.createtextFile("C:\Users\SMS\Desktop\invoices.txt")
Set invoiceLines = CurrentDb.OpenRecordset("select * from [tblBilling query]
order by orderID, custID")
strBlanks = " "
prevOrderID = invoiceLines!orderID
prevCustID = invoiceLines!custID
prevOrderDate = invoiceLines!orderDate
prevContact = invoiceLines!Contact
orderTotal = 0#
Do Until invoiceLines.EOF

If I open the module and click on “Runâ€, “Run Sub/UserForm†the module runs
and produces a text file we need.

I would like this module to run when a button on a form is pressed by the
user, but I don’t know what commands to put in the “On Click†Event Procedure
of the button to make this happen.

Can someone clue me in here?

Thanks,
Steve

Code the command button click event:

exportInvoices
 
Back
Top