DlookUp run time error 2465

divaam

Registered User.
Local time
Today, 11:47
Joined
Apr 30, 2019
Messages
18
I want to display the data to label when I choose 3 combobox
cmbIndi is the field that I want to display the data
cmbPub is the table
cmbTahun is the criteria from field "Tahun"

LblData.Caption = DLookup([cmbIndi.value], [cmbPub.value], "[Tahun]=" & [cmbTahun.value])

There are run time error '2465'
Microsoft Access can't find the field '|1' referred ti in your expression

Can anyone fix this?
 

Attachments

Firstly you can stop using .Value, that is the default property, so that will save you some typing.
Secondly, if cmdTahun is text you need to surround with single quote or two double quotes. If dates surround with #

I would also use the me prefix to signify the form control.?
Try
Code:
Me.LblData.Caption = DLookup(Me.cmbIndi, Me.cmbPub, "Tahun='" & Me.cmbTahun & "'")

HTH

Edit:
OK cmbTahun is numeric, however you do not have a field in the tables called tahun.?
 
Last edited:
Just what are you trying to do here.?
Notice I had to add the NZ function to get you label caption to work, and also remove data from A1 in table A to get the findfirst to work?:confused:

Code:
Private Sub cmdCari_Click()

Dim StrSQL As String
Dim search As String
Dim rs As Recordset
Dim nilai As String
Dim tabel As String
   
search = Me.cmbTahun
tabel = Me.cmbPub
Set rs = CurrentDb.OpenRecordset(tabel, dbOpenSnapshot, dbReadOnly)
rs.FindFirst "[" & Me.cmbIndi & "] is null and [Year]=" & Me.cmbTahun

If rs.NoMatch Then
    MsgBox ("No Match!")
    DoCmd.Close
    DoCmd.OpenForm "Entri Data"
Else
    'LblData.Caption = rs(" & Me.cmbIndi.Value & " = Null And (Tahun) = search).Value
    Me.LblData.Caption = Nz(DLookup(Me.cmbIndi, Me.cmbPub, "Year=" & Me.cmbTahun), "Is Null")
    Me.Label3.Visible = True
    Me.LblData.Visible = True
End If
End Sub
 
thank you so much, it did work! So happy, thank you once again
 
Just what are you trying to do here.?
Notice I had to add the NZ function to get you label caption to work, and also remove data from A1 in table A to get the findfirst to work?:confused:

Code:
Private Sub cmdCari_Click()

Dim StrSQL As String
Dim search As String
Dim rs As Recordset
Dim nilai As String
Dim tabel As String
   
search = Me.cmbTahun
tabel = Me.cmbPub
Set rs = CurrentDb.OpenRecordset(tabel, dbOpenSnapshot, dbReadOnly)
rs.FindFirst "[" & Me.cmbIndi & "] is null and [Year]=" & Me.cmbTahun

If rs.NoMatch Then
    MsgBox ("No Match!")
    DoCmd.Close
    DoCmd.OpenForm "Entri Data"
Else
    'LblData.Caption = rs(" & Me.cmbIndi.Value & " = Null And (Tahun) = search).Value
    Me.LblData.Caption = Nz(DLookup(Me.cmbIndi, Me.cmbPub, "Year=" & Me.cmbTahun), "Is Null")
    Me.Label3.Visible = True
    Me.LblData.Visible = True
End If
End Sub


helo
I still have a run time error whe I develop this syntax

Me.LblData.Caption = DLookup(Me.cmbIndi, Me.cmbPub, "[Tahun]=" & Me.cmbTahun)

the access said run-time error '3075'
syntax error (missing operator) in query expression 'Total Hotel'

where 'Total Hotel' is the value of cmbIndi
can you help me what's wrong?
 
helo
I still have a run time error whe I develop this syntax

Me.LblData.Caption = DLookup(Me.cmbIndi, Me.cmbPub, "[Tahun]=" & Me.cmbTahun)

the access said run-time error '3075'
syntax error (missing operator) in query expression 'Total Hotel'

where 'Total Hotel' is the value of cmbIndi
can you help me what's wrong?

This is a duplicate thread. Please continue the discussion there.
 

Users who are viewing this thread

Back
Top Bottom