Running a function from a command button

R

Robin Chapple

This is my first use of a function.

I have copied a function and edited to suit my purposes. If I use F5
from the function it runs as planned.

How do I get it to operate from a command button?

Thanks,

Robin Chapple
 
T

Tom Lake

Robin Chapple said:
This is my first use of a function.

I have copied a function and edited to suit my purposes. If I use F5
from the function it runs as planned.

How do I get it to operate from a command button?

Add the function name to the button's OnClick event.

Tom Lake
 
R

Robin Chapple

Please remember that this is my first attempt.

I have tried the function name from the list on the module page,
("MembersExport"), and also from within the function. Code is below.

Each time the error message says "Can't find the macro"

I have used the expression builder which gave me this:

=[ImportDelimitedTextFile]

and an error message which says:

"The object does not contain the automation object
'ImportdelimitedTextFile'.

=====Code Follows =========

Option Compare Database
Option Explicit

'This function takes the following arguments
'strTextFilePath - The location of the Text File to be imported
'strTextFileName - The name of the Text File with its filename
extension (eg USHolidays.csv)
'strImportSpecName - The name of the Import Specification that you
created using the Import Text File Wizard
'strTableName - The Access table that you wish to create or populate
with the data from your imported text file
'blnHasFieldNames - Whether the file to be imported has field names as
its first row TRUE/FALSE
Function ImportDelimitedTextFile(strTextFilePath As String,
strTextFileName As String, strImportSpecName As String, _
blnHasFieldNames As Boolean, strTableName As String) As Boolean

DoCmd.TransferText TransferType:=acImportDelim,
SpecificationName:=strImportSpecName, TableName:=strTableName, _
FileName:=strTextFilePath & "\" & strTextFileName,
HasFieldNames:=blnHasFieldNames
'Set the return code of this function call in case we need to use it
later on for error trapping.....
ImportDelimitedTextFile = True
End Function

'Use this procedure to call the ImportDelimitedTextFile over and over
for each file we wish to import into a table.
Sub ImportMyTextFiles()
Dim blnRC As Boolean

'Import the D9790Database file into its own table
blnRC = ImportDelimitedTextFile(strTextFilePath:="E:\Downloads",
strTextFileName:="MembersExport.csv", _
strImportSpecName:="tMembersExport Link Specification",
blnHasFieldNames:=True, strTableName:="tMembersExport")

End Sub

Thanks,

Robin Chapple
 
M

Mikal via AccessMonster.com

Hi, Robin:

Since you don't seem to have an answer you understand yet. I'll give it a
shot.

In the button's on click event, use the following code

Private Sub NameOfYourButton_Click()
NameOfYourFunction
End Sub


Robin said:
Please remember that this is my first attempt.
[quoted text clipped - 6 lines]
 

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