DColin
asked on
Can not write values to Db in Access form.
Hi Experts,
Please consider the code snippet below.
When a combo box selection is made I want that value (cboManpower.Text) along with another value (txtIDNumber.Text ) from the same form to be written to the tblPersonel tabel of the Manpower.accb database.
I am receiving an error saying that I can not reference the property of a control unless it has focus.
Private Sub cboManpower_Change()
Dim dbs as Database
Set dbs = OpenDatabase("Manpower.acc db")
dbs.Execute "INSERT INTO tblPersonel (IDNumber, FullName) VALUES (" & Me.txtIDNumber.Text & ", '" & Me.cboManpower.Text & "');"
dbs.Close
End Sub
Please consider the code snippet below.
When a combo box selection is made I want that value (cboManpower.Text) along with another value (txtIDNumber.Text ) from the same form to be written to the tblPersonel tabel of the Manpower.accb database.
I am receiving an error saying that I can not reference the property of a control unless it has focus.
Private Sub cboManpower_Change()
Dim dbs as Database
Set dbs = OpenDatabase("Manpower.acc
dbs.Execute "INSERT INTO tblPersonel (IDNumber, FullName) VALUES (" & Me.txtIDNumber.Text & ", '" & Me.cboManpower.Text & "');"
dbs.Close
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Because there is a Default Property. In the case of a Text box ... it's the Value property.
The .Text property is more often associated associated with a combo box, whose Default Property is also the Value property.
The difference is ... the .Text property is the 'value' currently in a Text or Combo box ... *before* the Text or Combo Box is updated, ie before the AfterUpdate event occurs when you exit either ... at which time the new Value is in effect.
So for example, if you are say replacing a value in a Text box by say typing over an existing value ... the .Text property will given you that text at any moment while typing. The .Value property is still the original value ... until you exit the Text box.
The Focus issue is a special nuance of the .Text property.
= = =
The .Text property is more often associated associated with a combo box, whose Default Property is also the Value property.
The difference is ... the .Text property is the 'value' currently in a Text or Combo box ... *before* the Text or Combo Box is updated, ie before the AfterUpdate event occurs when you exit either ... at which time the new Value is in effect.
So for example, if you are say replacing a value in a Text box by say typing over an existing value ... the .Text property will given you that text at any moment while typing. The .Value property is still the original value ... until you exit the Text box.
The Focus issue is a special nuance of the .Text property.
= = =
The only event you can use to refer to a controls .text property is the OnChange event of that specific control.
ASKER
Do you know why this would work. How does the interpreter know what property to use when it is not referenced?