problem while updating table data in forms in MS access 2003

R

ravishankar

h

i am getting stuck while updating the data in the database table usin
a command button. the code is as follows and i am getting th
following error: " run time 2185: you cant reference a property o
method for a control unless the control has focus" and th
"query=......." line of the code gets highlighted in yellow

Private Sub Command10_Click(
Dim query As Strin

query = "select RESOURCEINFO from tbl_control where CONTROLNAME='"
Combo4.Text + "'

If (cn.State <> 1) The
cn.Open "dsn=ABC", "", "
End I
rs.Open query, cn, adOpenKeyset, adLockOptimisti
RESOURCEINFO.SetFocu
rs.Fields(0) = RESOURCEINF
rs.Updat

rs.Clos
Set rs = Nothin
cn.Clos
Set cn = Nothin
On Error GoTo Err_Command10_Clic

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord,
acMenuVer7

Exit_Command10_Click
Exit Su

Err_Command10_Click
MsgBox Err.Descriptio
Resume Exit_Command10_Clic

End Su

i am a beginner. any help would be really of great help
 
N

Nikos Yannacopoulos

Ravishankar,

The problem is that you are referencing the combo's Text property, which
you can only do when the combo has the focus (thus the error message).
The good news is you don't need to reference it at all, as what you
actually want is the value, returned by default if no property is
referenced explicitly. In other words, all you need to do is change the
expression to:

query = "select RESOURCEINFO from tbl_control where CONTROLNAME='" +
Combo4 + "'"
(watch out for wrapping! should be a single line)

HTH,
Nikos
 
Top