Run a module from a button on a form

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
 
F

fredg

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
 
S

Steve in S.F.

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
 

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