VBA Import

Jackass

New Member
Joined
Jul 16, 2015
Messages
4
I have 1 text0=to show path file to be import
1 cmdBrowse = Browse file exel to import
1 cmdImportPlan =for import to table when click
but when i select file it's show error in " DoCmd.TransferSpreadsheet acImport, 8, "tblPlan", Fname, True, "A1:G100"


anyone help me?

this is my coding

Public Function Filename(ByVal strPath As String, sPath) As String
sPath = Left(strPath, InStrRev(strPath, "\"))
Filename = Mid(strPath, InStrRev(strPath, "\") + 1)

End Function
Private Sub Form_Load()
Text0.Value = ""
End Sub
Private Sub CmdBrowse_Click()
Dim f As Object


Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = Filename(f.SelectedItems(i), sPath)
Text0.Value = sPath & "" & sFile
Next
End If
End Sub
Private Sub CmdImportPlan_Click()
Dim Fname As String
Fname = Text0.Value
Dim LResponse As Integer




If Me.Text0.Value = "" Then
LResponse = MsgBox("Please select file to import!!!", vbOKOnly, "Select File")

ElseIf Me.Text0.Value <> "" Then
LResponse = MsgBox("Do you want to import this file to the system?", vbYesNo, "Confirmation")
If LResponse = vbYes Then
DoCmd.TransferSpreadsheet acImport, 8, "tblPlan", Fname, True, "A1:G100"
LResponse = MsgBox("Import completed", vbOKOnly, "Confirmation")
Me.Text0.Value = ""
Else: LResponse = MsgBox("Cancel import", vbOKOnly, "Confirmation")
End If
End If
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
instead of the import command,
do:
copy the xl sheet to a generic name, like: file2import.xls
attach the excel file, sheet , as a table
then run an append query.

then the algorithm will be
1.save xl file to file2import.xls
2.run append query macro.
done
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top