emilios
emilios

Reputation: 375

Can not find the Field name

strSQL = " SELECT W.wrhID, " & _
         " W.wrhName AS WName " & _
         " FROM tblWarehouse AS W " & _
         " WHERE W.wrhID IN ( " & Forms.frmStockControl.Form.txtwrhIDs & " )"
Set rst = CurrentDb.OpenRecordset(strSQL)
 Do Until rst.EOF
    Dim strlbl$, strlblV$
    For i = 1 To rst.Fields.count
        strlbl = "Me.lblWarehouse" & i
        strlblV = "Me.lblWarehouse" & i
        Me.Controls(strlbl).Caption = rst!WName
        Me.Controls(strlblV).visible = True
    Next
    rst.MoveNext
 Loop

I am getting error msg 2465 - Can not find the Field name

but field Name exists in my form.
Pls help.

Upvotes: 0

Views: 56

Answers (2)

emilios
emilios

Reputation: 375

i changed

strlbl = "Me.lblWarehouse" & i
strlblV = "Me.lblWarehouse" & i 

to :

strlbl = "lblWarehouse" & i
strlblV = "lblWarehouse" & i 

and is working fine

Upvotes: 0

PhilS
PhilS

Reputation: 1661

The correct syntax to addres a form control in VBA is either:

Forms![YourFormName]![YourControlName]

The brackets are only required if the name contains blanks.

or

Forms("YourFormName").Controls("YourControlName")

Upvotes: 2

Related Questions