Macro?????

Dgavilanes

Registered User.
Local time
Today, 02:30
Joined
Jun 25, 2001
Messages
109
I created a new macro in Access that import an excel file called Master into a MS Access, it works fine.

My question is I would like to get a dialog box to open when I run the macro and be able to type the name of the new excel file to be imported into Ms Access.

the current code is TransferSpreadsheet
file named: d:/TGreen_V1/Master~1.xls

if possible please let me know

Thanks

Dennis
 
i would suggest making up your own form to appear
as a dialogue box.set the forms modal property to yes
pop up to yes,bordertype to dialogue
put a command button and a text box on this form

if you have a lot of excel files i would suggest
using a combo box filled with the file names

in the form where your macro is triggered
replace your macro name with an event procedure


in the event procedure paste this code and replace the red text
''''''''''''''''''''''''''''''''''''''''
DoCmd.OpenForm "the daialogueformname"
'''''''''''''''''''''''''''''''''''''''''
file named: d:/TGreen_V1/Master~1.xls
i have assumed the filename you want to type in would be Master in the
following code
on your pop up form command button use the onclick event to
fire another event procedure




in the event procedure paste this code and replace the red text
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim CtlName As Control
Set CtlName = Me![textboxnamethat holds excelfilename]
'test to see if there is a name
If IsNull(CtlName) Then
Beep
MsgBox "Excel File Name Required", vbOKOnly, "File Name Required"
Exit Sub
End If

On Error GoTo HandleError:
Dim ExcelFileName As String
Dim StrPath As String
ExcelFileName = CtlName
StrPath = "d:/TGreen_V1/" & ExcelFileName & "~1.xls"

DoCmd.TransferSpreadsheet acImport, 8, "thenameofthetabletoimportto", StrPath, False, ""
MsgBox "Transfer Complete", vbOKOnly, "Congralulations"

ExitHere:
Exit Sub
DoCmd.Close acForm, "popupformName"

HandleError:

MsgBox "No Excel File Found At " & CtlName
Resume ExitHere:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
i hope this is not to confusing
 
macro

thanks for your reply

I will give it a try and see what happens.

have a nice weekend
Dennis
 

Users who are viewing this thread

Back
Top Bottom