Doubt regarding modifying a record in a table

shandoo27

Registered User.
Local time
Yesterday, 16:07
Joined
May 20, 2010
Messages
30
I wish to modify a row in the table on the click of the modify button . I tried to use UPdate SQL command and run the SQL command using DoCmd.RunSQL. It is not showing any error but it is not modifying the row .

the Code for the above requirement i wrote was :

Dim SQLC As String
SQLC = "Update ACTUALS SET EST_EF_T =FORMS![ACTUALS]!EST_EF_T AND ACT_EF_T=FORMS![ACTUALS]!ACT_EF_T AND EST_ST_DT=FORMS![ACTUALS]!EST_END_DT AND ACT_ST_DT=FORMS![ACTUALS]!ACT_ST_DT AND ACT_END_DT=FORMS![ACTUALS]!ACT_END_DT WHERE PRJT_NAME= FORMS![ACTUALS]!PRJT AND TLA= FORMS![ACTUALS]!SUB_PRJT AND CAT= FORMS![ACTUALS]!CATEGORY AND TASK=FORMS![ACTUALS]!TSK AND ACTIVITY=FORMS![ACTUALS]!ACTIV; "
DoCmd.RunSQL SQLC

Could anyone guide me as to what mistake i am doing .

thanks for the help in advance.
 
First you don't use "AND" to seperate the different fields in your table to update, you use COMMA ",".

Second, since you dont have a WHERE-CLAUSE in yor statement, then ALL the records in your table will be the same.

Third, to refrence a control on a form you can shorten the expression from:

[FORMS![ACTUALS]!EST_EF_T to Me!est_ef_t but you must use enclose the refrence in quotes.

For text fields:
Code:
est_ef_t = '" & Me!est_ef_t & "'

For numbers:
Code:
est_ef_t = " & Me!est_ef_t & "

To test a SQL-string for syntax use either

Code:
Debug.Print SQLC
or
Code:
MsgBox SQLC
before you execute the SQL

And finally why do you not BIND the form directly to the table? Then you can edit the record directly from the form, without all this VBA hocus pocus. ;)

JR
 

Users who are viewing this thread

Back
Top Bottom