Writing values into a table via VBA

G

Guest

I have two forms, lets call them A & B, A forms Record Source is from Table A
and B Forms record source is from table B.

On the open event of the A form, if certain conditions are true then change
value of field "Startdate" located in table B. table B only has 1 row of
information

Can someone point me in the right direction eg some sample code which is
used to write/change field values located in different tables
 
G

Guest

You can use update SQL

'If the value you want to update come from the form, and the type of the
field is a number then use
Docmd.RunSQL "UPDATE TableName SET TableName.FieldName = " &
Me.[FieldNameInForm]
==============================
'The type of the field is a Text then use
Docmd.RunSQL "UPDATE TableName SET TableName.FieldName = '" &
Me.[FieldNameInForm] & "'"
==============================
'The type of the field is a Date then use
Docmd.RunSQL "UPDATE TableName SET TableName.FieldName = #" &
Me.[FieldNameInForm] & "#"

If you want to suppress the update message, then set the warnings to false

Docmd.SetWarnings False
Docmd.RunSQL "...."
Docmd.SetWarnings True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top