admin管理员组

文章数量:1302275

I'm using a Excel 2016 with Database Access 2016 too. At home the code run perfectly, but in my office the same file getting a error in this line:

varX = DLookup("[Código]", "Campanha", "[Cod Produto] = " & EntradaBD.Fields("Cod Produto").Value & "")

Interesting when I open manually DB file the error is gone, but when BD is open programmatically I get this error: 2950 - reserved error. My BD open normally, and even though I have placed file in a trusted place.

Thanks for read this.

UPDATE: When i arrived at home, same problem now: 2950 reserved error . But his line worked yesterday and i dont edit file.

UPDATE2: I realized that Dlookup only works when the database file is open, that is, with MSAccess on the screen. All other DB access functions work with the file closed, but DlookUp insists on error 2950, ​​what could it be?

UPDATE3:

Private Sub cbgrupo_Change()
Dim fonteBD As String
Dim varX As Variant

Set EntradaBD = New ADODB.Recordset

ConectaAccess

If Me.cbgrupo.Value = "TODOS" Then
    fonteBD = "Select * FROM [BancoDados] WHERE [Grupo] is not null ORDER BY [Cod Produto]"
Else
    fonteBD = "Select * FROM [BancoDados] WHERE [Grupo] = '" & Me.cbgrupo.Value & "' ORDER BY [Cod Produto]"
End If
EntradaBD.Open fonteBD, conectabd, adOpenKeyset, adLockReadOnly

If Not (EntradaBD.EOF And EntradaBD.BOF) Then
    EntradaBD.MoveFirst 
    
    Do Until EntradaBD.EOF = True
    varX = DLookup("[Código]", "Campanha", "[Cod Produto] = " & EntradaBD.Fields("Cod Produto").Value)
    If IsNull(varX) Then
        Me.ListBox1.AddItem EntradaBD.Fields("Cod Produto").Value
        Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = EntradaBD.Fields("Produto").Value
    End If

    EntradaBD.MoveNext
    Loop
    
End If

If Not EntradaBD Is Nothing Then EntradaBD.Close


'fecha a conexão com o BD
DesconectaAccess

本文标签: excelVBA DLookUp returns error 2950 reserved errorStack Overflow