Updating a table from a form

  • Thread starter Thread starter alaxmen
  • Start date Start date
A

alaxmen

I have a form that has three (3) fields on it. Two of the fields are
currently in the db and the third is new info. I am trying to compare
the fields with the table and post the third into that particular
record. I have been experimenting with my own insanity and need help.
My last try at this was to use a query behind a cmd button. The query
is stated below. Any help would be appreciated because the answer just
escapes me and I know it is in from of my eyes.

INSERT INTO [TimeSheet]![OutTime]
WHERE (((TimeSheet.UserName)=[Forms]![frmOutTimeCard]![UserName]) AND
((TimeSheet.Date)=[Forms]![frmOutTimeCard]![Date]) AND
((TimeSheet.OutTime)=[Forms]![frmOutTimeCard]![OutTime]));

It is the last field I am trying to the table based on finding the
"username and date".
 
(e-mail address removed) wrote in @p10g2000cwp.googlegroups.com:
I have a form that has three (3) fields on it. Two of the fields are
currently in the db and the third is new info. I am trying to compare
the fields with the table and post the third into that particular
record.

I don't completely understand this. It appears to say that you want to
write into a table a third column, which will be some kind of value
derived from the other two. If that is the case then Just Don't Do That.
It's slow and it will be out of date as soon as one of the other values
changes. Use a SELECT query to generate the new data whenever you need to
see it. If that is not what you want, just ignore this paragraph!

INSERT INTO [TimeSheet]![OutTime]
WHERE (((TimeSheet.UserName)=[Forms]![frmOutTimeCard]![UserName]) AND
((TimeSheet.Date)=[Forms]![frmOutTimeCard]![Date]) AND
((TimeSheet.OutTime)=[Forms]![frmOutTimeCard]![OutTime]));

Well, no; this does not make any sense at all! The INSERT statement is
used to create new records in a table, and the syntax is

INSERT INTO TimeSheet (
UserName,
SomeDate,
OutTime
)
VALUES (
Forms!formOutTimeCard!UserName,
Forms!frmOutTimeCard!SomeDate,
Forms!frmOutTimeCard!OutTime
)


but I am not sure that is what you want to do..? You might want some kind
of update, which will write to a particular record:

UPDATE TimeSheet
SET OutTime = Forms!frmOutTimeCard!OutTime
WHERE UserName = Forms!frmOutTimeCard!UserName
AND SomeDate = Forms!frmOutTimeCard!SomeDate

By the way, using a fieldname like "Date" is a Really Bad Thing To Do,
because it is a reserved word in just about every language there is,
including SQL and VBA. Although it is legal, you have to remember to use
the [brackets] everywhere and it will turn into a bug and bite you.

Hope that helps


Tim F
 
Back
Top