Private Sub cmdGetFile_Click() On Error GoTo ImportErr Dim cld As New clsComDlg Dim strPath As String Dim ret As String cld.OpenFileDlg strPath = cld.FileName If (strPath <> "") Then Select Case Frame1.Value Case 1 DoCmd.RunSQL "DELETE * FROM MT_HAISO;" DoCmd.TransferText acImportDelim, _ "MT_HAISO", "MT_HAISO", strPath, False, "" Case 2 DoCmd.RunSQL "DELETE * FROM MT_VENDER;" DoCmd.TransferText acImportDelim, _ "MT_VENDER", "MT_VENDER", strPath, False, "" Case 3 DoCmd.RunSQL "DELETE * FROM MT_ITEM;" DoCmd.TransferText acImportDelim, _ "MT_ITEM", "MT_ITEM", strPath, False, "" Case 4 DoCmd.RunSQL "DELETE * FROM T_SHIP;" DoCmd.TransferText acImportDelim, _ "T_SHIP", "T_SHIP", strPath, False, "" End Select ret = MsgBox("读取完成", vbOKOnly, "Fresh Line Express") Else MsgBox "读取中止" End If Set cld = Nothing Exit Sub ImportErr: MsgBox "读取失败" Set cld = Nothing Exit Sub End Sub #If VBA7 Then Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OpenFilename) As Long 'Structure of Opend File Private Type OpenFilename lStructSize As Long hwndOwner As LongPtr hInstance As LongPtr lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long m_intFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As LongPtr lpfnHook As LongPtr lpTemplateName As String '#if (_WIN32_WINNT >= 0x0500) pvReserved As LongPtr dwReserved As Long FlagsEx As Long '#endif // (_WIN32_WINNT >= 0x0500) End Type #Else Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OpenFilename) As Long 'Structure of Opend File Private Type OpenFilename lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long m_intFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type #End If 'The Name of Opened File About Getting Dialogue Private m_strFileName As String 'The Title of File Private m_strFileTitle As String '/////////////////////////////////////////// '2015/05/25 '/////////////////////////////////////////// Public Sub OpenFileDlg() Dim tOpenFile As OpenFilename 'The Max Value of The Opened File Dim lngMaxSize As Long Dim strFileName As String Dim lngReturn As Long On Error GoTo ShowFileDialogError lngReturn = 0 lngMaxSize = 255 strFileName = "" 'Fill the room at The Space While Len(strFileName) < lngMaxSize - 1 strFileName = strFileName & " " Wend strFileName = strFileName & vbNullChar 'Setting of The Structure With tOpenFile .lStructSize = LenB(tOpenFile) .hwndOwner = 0 .lpstrFilter = "*.*" & vbNullChar .m_intFilterIndex = 0 .lpstrFile = strFileName .nMaxFile = lngMaxSize .lpstrInitialDir = "C:\" & vbNullChar .lpstrTitle = "Open The File" & vbNullChar 'Only for The Reading .flags = 1 .lpstrDefExt = 0 End With 'Pass The API & Indication Dialogue lngReturn = GetOpenFileName(tOpenFile) 'Check The Return Value Select Case lngReturn '0 meaning "Cancel" Case 0 Exit Sub '1 meaning The Acquisition of The File Name Case 1 m_strFileName = _ Left(tOpenFile.lpstrFile, InStr(tOpenFile.lpstrFile, vbNullChar) - 1) m_strFileTitle = "" End Select Exit Sub ShowFileDialogError: Exit Sub End Sub '/////////////////////////////////////////// '/////////////////////////////////////////// Public Property Get FileName() As String FileName = m_strFileName End Property