You can not refrence a property or method for a control unle

siamandm
BronzeLounger
Posts: 1263
Joined: 01 May 2016, 09:58

You can not refrence a property or method for a control unle

Post by siamandm »

Hello ,

im trying to change the caption of a label based on a combo box using this code below:

Code: Select all

If Me.cboZone.Text = "in camp" Then
    Me.lblTentHouse.Caption = " Tent No "
    Else
    Me.lblTentHouse.Caption = " House No"
    End If

the label and the combo box are inside a subfrom
i want to change the caption of the label when the form load or current event of the form
but i get this error:

You can not reference a property or method for a control unless the control has the focus

any help please

User avatar
HansV
Administrator
Posts: 78617
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: You can not refrence a property or method for a control

Post by HansV »

The Text property of a text box or combo box is only available while the user is editing that control. In all other situations, you must refer to the value of the control.

Let's say that "in camp" corresponds to ZoneID = 1. Use

Code: Select all

    If Me.cboZone = 1 Then
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1263
Joined: 01 May 2016, 09:58

Re: You can not refrence a property or method for a control

Post by siamandm »

thanks Hans
now i got it ....
regards