0
votes

I have a form which has a button that has a click procedure. Essentially if a checkbox(chkIncludeIDs) is ticked then it has to open a form and make the property of a textbox on that form visible.

My current code for the click event is as follows;

Private Sub Update_pending_Click() On Error GoTo Err_Update_pending_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.chkIncludeIDs = 0 Then
    stDocName = "Pending Queries Locked"
Else
    stDocName = "Pending Queries Locked"
    Forms![Pending Queries Locked]!ID.Visible = True
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Update_pending_Click: Exit Sub

Err_Update_pending_Click: MsgBox Err.Description Resume Exit_Update_pending_Click

End Sub

The form that I open is "Pending Queries Locked" The textbox I need making visible is ID as it's default value is visible = false

For some reason my code isn't working and I'm a little unsure why. :/

1

1 Answers

0
votes

please name your controls without spaces like "form_pending_queries_locked", query_my_query, txt_id, lbl_id for many good reasons.

when you access a control's property you need to specify which property you are accessing. e.g

If Me.chkIncludeIDs.value <> 0 Then

regarding your question. You need to open the form first before accessing its controls. so that would be logically: open the form, access the control, change its property.

in code it would be

Dim txt_id As Textbox
DoCmd.OpenForm "frm_myform"
Set txt_id = Forms![frm_myform]!txt_id

txt_id.visible = False

or alternatively: you can send a parameter via OpenArg and access it via on form_load event which will then change local controls properties..