2014-10-06 77 views
-1

请参考下面的代码...3146 ODBC调用失败 - 访问2010

Private Sub Save_Click() 
    On Error GoTo err_I9_menu 
    Dim dba As Database 
    Dim dba2 As Database 
    Dim rst As Recordset 
    Dim rst1 As Recordset 
    Dim rst2 As Recordset 
    Dim rst3 As Recordset 
    Dim SQL As String 
    Dim dateandtime As String 
    Dim FileSuffix As String 
    Dim folder As String 
    Dim strpathname As String 
    Dim X As Integer 

    X = InStrRev(Me!ListContents, "\") 

    Call myprocess(True) 

    folder = DLookup("[Folder]", "Locaton", "[LOC_ID] = '" & Forms!frmUtility![Site].Value & "'") 
    strpathname = "\\Reman\PlantReports\" & folder & "\HR\Paperless\" 
    dateandtime = getdatetime() 

    If Nz(ListContents, "") <> "" Then 
    Set dba = CurrentDb 

    FileSuffix = Mid(Me!ListContents, InStrRev(Me!ListContents, "."), 4) 

    SQL = "SELECT Extension FROM tbl_Forms WHERE Type = 'I-9'" 
    SQL = SQL & " AND Action = 'Submit'" 

    Set rst1 = dba.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges) 

    If Not rst1.EOF Then 
     newname = Me!DivisionNumber & "-" & Right(Me!SSN, 4) & "-" & LastName & dateandtime & rst1.Fields("Extension") & FileSuffix 
    Else 
     newname = Me!DivisionNumber & "-" & Right(Me!SSN, 4) & "-" & LastName & dateandtime & FileSuffix 
    End If 

    Set moveit = CreateObject("Scripting.FileSystemObject") 

    copyto = strpathname & newname 
    moveit.MoveFile Me.ListContents, copyto 

    Set rst = Nothing 
    Set dba = Nothing 

    End If 

    If Nz(ListContentsHQ, "") <> "" Then 
    Set dba2 = CurrentDb 

    FileSuffix = Mid(Me.ListContentsHQ, InStrRev(Me.ListContentsHQ, "."), 4) 

    SQL = "SELECT Extension FROM tbl_Forms WHERE Type = 'HealthQuestionnaire'" 
    SQL = SQL & " AND Action = 'Submit'" 

    Set rst3 = dba2.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges) 

    If Not rst3.EOF Then 
     newname = Me!DivisionNumber & "-" & Right(Me!SSN, 4) & "-" & LastName & dateandtime & rst3.Fields("Extension") & FileSuffix 
    Else 
     newname = Me!DivisionNumber & "-" & Right(Me!SSN, 4) & "-" & LastName & dateandtime & FileSuffix 
    End If 

    Set moveit = CreateObject("Scripting.FileSystemObject") 

    copyto = strpathname & newname 
    moveit.MoveFile Me.ListContentsHQ, copyto 

    Set rst2 = Nothing 
    Set dba2 = Nothing 

    End If 

    Set dba = CurrentDb 

    Set rst = dba.OpenRecordset("dbo_tbl_EmploymentLog", dbOpenDynaset, dbSeeChanges) 

    rst.AddNew 
    rst.Fields("TransactionDate") = Date 
    rst.Fields("EmployeeName") = Me.LastName 
    rst.Fields("EmployeeSSN") = Me.SSN 
    rst.Fields("EmployeeDOB") = Me.EmployeeDOB 
    rst.Fields("I9Pathname") = strpathname 
    rst.Fields("I9FileSent") = newname 
    rst.Fields("Site") = DLookup("Folder", "Locaton", "Loc_ID='" & Forms!frmUtility!Site & "'") 
    rst.Fields("UserID") = Forms!frmUtility!user_id 
    rst.Fields("HqPathname") = strpathname 
    rst.Fields("HqFileSent") = newname2 
    rst.Update 

    Set dba = Nothing 
    Set rst = Nothing 

exit_I9_menu: 
    Call myprocess(False) 
    DivisionNumber = "" 
    LastName = "" 
    SSN = "" 
    ListContents = "" 
    ListContentsHQ = "" 
    Exit Sub 

err_I9_menu: 
    Call myprocess(False) 
    MsgBox Err.Number & " " & Err.Description 
    'MsgBox "The program has encountered an error and the data was NOT saved." 
    Exit Sub 

End Sub 

我不断收到ODBC调用错误。这些权限都是正确的,前面的一段代码在I9和Hq日志有单独表的地方工作。当有人提交一组包含特定信息的文件时,将调用该例程。

+1

这是你发布的很多代码。它失败的是什么? 'rst.Update'? – mwolfe02 2014-10-06 20:30:48

回答

0

我解决了这个通过重新创建表的SQL,而不是向上调整其进出的。

3

这里只是一个猜测,但我认为你有一个错误,导致分配一个NULL到必填字段。

更改 “Locaton”:

rst.Fields("Site") = DLookup("Folder", "Locaton", "Loc_ID='" & Forms!frmUtility!Site & "'") 

要 “位置”:

rst.Fields("Site") = DLookup("Folder", "Location", "Loc_ID='" & Forms!frmUtility!Site & "'") 

排除故障3146 ODBC错误某些一般性的建议:DAO有一个Errors collection通常包含更具体的信息对于ODBC错误。以下是查看内容的快速和肮脏的方法。我有一个标准的错误处理模块中的这种更精细的版本,我包括我所有的计划:

Dim i As Long 
For i = 0 To Errors.Count - 1 
    Debug.Print Errors(i).Number, Errors(i).Description 
Next i 
+0

感谢您的回复。其实Locaton是正确的它的名字的一张桌子。我已经解决了这个问题。每个记录都有一个唯一的标识符,并且不想创建标识符。 – designspeaks 2014-10-07 11:57:19

+2

请花时间发布您采取的步骤来解决问题并接受您的答案,以便将来可以帮助其他人。 – mwolfe02 2014-10-07 14:28:55

+1

@ mwolfe02你的快速和肮脏的4行代码只是帮助我解决了我的3146错误。谢谢! – PKatona 2017-04-13 21:38:02