执行VBA模块时Access DB无响应

时间:2018-09-21 18:42:29

标签: vba ms-access module

我有一个Access数据库,该数据库正在使用标准宏从.csv文件中输入信息。我想要更多的错误处理和更多的输入清理功能,所以我转换为VBA代码。在我的测试数据库中,一切都很好,但是当我将代码转移到转换后的宏代码中后,一旦执行,它将冻结数据库,但仅冻结主窗体区域。工具栏都仍然处于活动状态。就像数据库的绘制函数挂了一样。现在我知道在执行vba代码时主窗体代码将停止,但是据我所知,vba即将到达其功能的结尾并点击End Function。没有循环。我已注释掉所有错误处理和GoTo语句,但它仍然存在。即使在注释掉我所有添加的内容并仅保留原始转换后的宏代码之后,它仍然持续存在。有什么想法为什么会挂断电话?下面的代码。即使关闭了vba编辑器。它不会还原它。

Option Compare Database  
Option Explicit  


Function Import_Arm_CSV()  
On Error GoTo Import_Arm_CSV_Err  
   ' Dim StringVar As String  
   ' Dim Initialinput As Variant  
   ' Dim FileName As String  
   ' Dim FilePath As String  
    DoCmd.SetWarnings False  
    DoCmd.Echo False, ""  
    DoCmd.OpenQuery "EMPTY_FIELDS", acViewNormal, acEdit  
    DoCmd.OpenQuery "EMPTY_CSV", acViewNormal, acEdit  
'TryAgain:  
    'Err.Clear  
    'Asks user for Filepath  
    'Initialinput = InputBox("Please enter file path", "Import", "")  
    'Ends Function if no input or cancel is detected  
   ' If Initialinput = "" Or Initialinput = False Then Exit Function  
    'Scrubs outer quotes if present  
   ' MsgBox (Initialinput & "Before")  
    'StringVar = Replace(Initialinput, Chr(34), "", 1, 2)  
    'On bad input sent to error handler  
    'On Error GoTo InputErrHandler  
    'informs about bad input and asks to try again or not  
'InputErrHandler:  
    'If MsgBox(Err.Description, vbRetryCancel, "Bad Input") = vbCancel Then   Exit Function  
    'Resume TryAgain  

    'MsgBox (StringVar & "After")  
   'Exit Function  
    DoCmd.TransferText acImportDelim, "11", "FIELDS_3", InputBox("Please enter file path", "Import", ""), True, ""  
    DoCmd.OpenQuery "APPEND_TO_CSV", acViewNormal, acEdit  
    DoCmd.OpenQuery "APPEND_TO_CSV2", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_FLAG", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_CONV", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_INDEX", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_INDEX_002", acViewNormal, acEdit  
    DoCmd.OpenQuery "update_udfdate1_", acViewNormal, acEdit  
    DoCmd.OpenQuery "ARM_UPDATE", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_ARMACAP", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_ZIP", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_TEXT_IDENTIFIERS", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_TYPE_", acViewNormal, acEdit  
    DoCmd.OpenQuery "APPEND_TO_TRUST", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_FALSE", acViewNormal, acEdit  
    DoCmd.OpenQuery "UPDATE_FALSE_DATE1", acViewNormal, acEdit  
    DoCmd.OpenQuery "DELETE_FALSE_DATE", acViewNormal, acEdit
    Beep  
    MsgBox "Data has been imported!", vbOKOnly, ""  


Import_Arm_CSV_Exit:  
    Exit Function  

Import_Arm_CSV_Err:  
    MsgBox Error$  
    Resume Import_Arm_CSV_Exit  

End Function 

1 个答案:

答案 0 :(得分:0)

您的问题是您将echo设置为false而不是重新启用它。 冻结Access应用程序后,您可以在立即窗口中重新启用echo。 只要记住在您的DoCmd.echo true末尾添加一个function