krishnak
05-24-2010, 04:13 PM
Hi All,
We have a Form on Access 2007 with two Textboxes and a button and the Form operates on the following code:
Public Sub btnShMetrics_Click()
'Declare local variables for the form.
Dim pName As String, divNr As String
txtPName.SetFocus
pName = Me.txtPName.Text
MsgBox (pName)
txtDivNr.SetFocus
divNr = Me.txtDivNr.Text
MsgBox (divNr)
End Sub
If I want to read the value in any Textbox, I have to set focus on that Textbox. Obviously we can set focus only on one control at any instant.
After reading the value in the second Textbox(txtDivNr), I lost focus on the first Textbox (txtPName).
This means, in a long sequence of operations, before reading/writing the value in any control, the code has to precede by
[Control].SetFocus
Is VBA in Access always like that? Maybe I am mistaken, it used to be simpler. I do not remember of explicitly setting the focus on each control.
Or have I done anything wrong in setting up the Form and the controls? The 'tab' control is working OK when tested.
I inserted 'unbound' Textboxes in the Form.
I'll appreciate any advice.
Thanks in advance
We have a Form on Access 2007 with two Textboxes and a button and the Form operates on the following code:
Public Sub btnShMetrics_Click()
'Declare local variables for the form.
Dim pName As String, divNr As String
txtPName.SetFocus
pName = Me.txtPName.Text
MsgBox (pName)
txtDivNr.SetFocus
divNr = Me.txtDivNr.Text
MsgBox (divNr)
End Sub
If I want to read the value in any Textbox, I have to set focus on that Textbox. Obviously we can set focus only on one control at any instant.
After reading the value in the second Textbox(txtDivNr), I lost focus on the first Textbox (txtPName).
This means, in a long sequence of operations, before reading/writing the value in any control, the code has to precede by
[Control].SetFocus
Is VBA in Access always like that? Maybe I am mistaken, it used to be simpler. I do not remember of explicitly setting the focus on each control.
Or have I done anything wrong in setting up the Form and the controls? The 'tab' control is working OK when tested.
I inserted 'unbound' Textboxes in the Form.
I'll appreciate any advice.
Thanks in advance