J
James D. Houston
I've been using vb6 to develop front ends for Access databases for some time
now. Now I have a client who would like to have their app written using
Access VBA, which I've never used before. The first thing I need is a form
that will let the user enter a name and search a table to see if the name is
already there. In VB6 I'd put the code in a command button's click event:
sFName = txtFirstName.Text
sLName = txtLastName.Text
If sFName <> vbNullString Then
sName = sFName & " " & sLName
Else
sName = vbNullString
sLName = txtLastName.Text
End If
GetPlayer sName, sLName
But when I try to run this code in Access, I get an error message saying
that: "You can't reference a property or method of a control unless the
control has the focus"
So how do I get the value of a control without setting the focus to that
control?
Another problem I'm having: I'd like to make sure the text boxes are blank
when I load the form. In vb6 I'd put something like this in the form's
initialize event:
Dim ctl As Control
For Each Control In Form_Form1.Controls
Set ctl = Form_Form1.ActiveControl
If ctl.ControlType = acTextBox Then
ctl.Text = vbNullString
End If
Next
I get the error message: "The expression you entered requires the control to
be in the active window"
Can anyone tell me how to do this in Access VBA? Thaniks in advance.
Jim
now. Now I have a client who would like to have their app written using
Access VBA, which I've never used before. The first thing I need is a form
that will let the user enter a name and search a table to see if the name is
already there. In VB6 I'd put the code in a command button's click event:
sFName = txtFirstName.Text
sLName = txtLastName.Text
If sFName <> vbNullString Then
sName = sFName & " " & sLName
Else
sName = vbNullString
sLName = txtLastName.Text
End If
GetPlayer sName, sLName
But when I try to run this code in Access, I get an error message saying
that: "You can't reference a property or method of a control unless the
control has the focus"
So how do I get the value of a control without setting the focus to that
control?
Another problem I'm having: I'd like to make sure the text boxes are blank
when I load the form. In vb6 I'd put something like this in the form's
initialize event:
Dim ctl As Control
For Each Control In Form_Form1.Controls
Set ctl = Form_Form1.ActiveControl
If ctl.ControlType = acTextBox Then
ctl.Text = vbNullString
End If
Next
I get the error message: "The expression you entered requires the control to
be in the active window"
Can anyone tell me how to do this in Access VBA? Thaniks in advance.
Jim