How do I use a text box control value in DoCmd.TransferSpreadsheet

A

Ayo

I have a form with a button and 4 text boxes on it, the button has the
following click event:

Private Sub cmdImportFiles_Click()
GetExcelFileData Me
End Sub
I want to loop through the text boxes on the, which are going to contain
file paths, and do DoCmd.TransferSpreadsheet to import excel files into my
database. I am have some problems with this, especially with "ctrl.Value" in
the following code.

Function GetExcelFileData(frmForm as Form)
Dim ctrl as Control

For Each ctrl In frmForm
If TypeName(ctrl) = "TextBox" And ctrl.Name="txtInscope" Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,"Inscope
Table", ctrl.Value,True
End if
Next ctrl
End Function

Any ideas how to do this?
 
P

Paul Shapiro

Omit the loop because you already know the control name you want to use.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,"[Inscope
Table]", Me.txtInscope.Value,True
 

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