Referencing controls in a Selection Criteria form for Reports

  • Thread starter Thread starter Barry G. Sumpter
  • Start date Start date
B

Barry G. Sumpter

Hi all,

I'm using the form generated in the Switchboard manager.

I've added a few combo boxes for selection criteria:
cboUser
cboCompany
cboProject
cboTask

I've a very simple report which just shows what user is assigned to what
company, project, task.

At the top of the report I want to show the selection criteria.

To build the selection criteria text I execute a routine after every
cboXXXX_Change

The problem:

To retrieve the text from each combo box I have to use:
cboxxx.setfocus

The setfocus causes a lot of flickering on the form.

as in:

Sub BuildReportCriteriaDisplays()


Dim strLabels As String
Dim strData As String

txtUser.SetFocus

If Trim(txtUser.Text) <> "" Then
strLabels = "User :"
strData = txtUser.Text
End If

cboCompany.SetFocus

If cboCompany.Value <> "" Then
If Trim(strLabels) <> "" Then
strLabels = strLabels & vbCrLf & "Company :"
strData = strData & vbCrLf & cboCompany.Text
Else
strLabels = "Company :"
strData = cboCompany.Text
End If
End If

etc....


Is there another way to reference properties a control on a form?


Thanks,
Barry G. Sumpter
 
The .text property of a control is ONLY valid while the control has focus.

You want as a matter of general coding to use:
If cboCompany.Value <> "" Then
strData = cboCompany


Just use cboCompany

or cboCompany.Value

Both are the same.Both can be use to set, or get values.

So, you RARELY will use .text.

The .text should only be used for events like on-change when you need to
work with the text of a control..but the control has NOT yet been updated...

So, in 99% of all you coding ...just use the control name, and you do NOT
have to worry about focus...
 
Cable modem has been down for the last day...

Thanks Albert that was it exactly...
 
Back
Top