By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

Update a Table

P: n/a
I have a very simple database. I have information in a form that I would
like to write to a table using some code. The table is called tblTest. The
field I would like to write to is called Date. The data which I would like
to write is Date(). Please can someone help me with this simple code?

Many Thanks,
John
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
news.btinternet.com wrote:
I have a very simple database. I have information in a form that I would
like to write to a table using some code. The table is called tblTest. The
field I would like to write to is called Date. The data which I would like
to write is Date(). Please can someone help me with this simple code?


Date is a reserved word in Access and it isn't very descriptive - I'd recommend
changing it to prevent problems but if you bracketed the field name you might
be successful with:

CurrentDb.Execute "INSERT INTO tblTest ([Date]) VALUES ( Date() )";

Of course you didn't give us enough info to say definitively. Is the form
bound to the tblTest table? Are you created a new record or updating an
existing? And you'll need more data for the record in tblTest such as a primary
key value.

Generally you bind your forms to a table or query by setting the form's
RecordSource property to that data source. Then you can bind controls to
fields in that datasource. Then modifying the value of the control updates
the bound field in the bound table/query.

--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 12 '05 #2

P: n/a
"news.btinternet.com" <te*****@btinternet.com> wrote in message
news:bu**********@sparta.btinternet.com...
I have a very simple database. I have information in a form that I would
like to write to a table using some code. The table is called tblTest. The
field I would like to write to is called Date. The data which I would like
to write is Date(). Please can someone help me with this simple code?

Many Thanks,
John

Normally, there would be no point writing code for this sort of thing. If
your form is bound to the table, then you can simply edit the data using the
form and if you needed, for example, today's date automatically entered in a
record then you could use the Date() function as the default value.

If you are certain you need (or want) to write code, then the first thing to
consider is where to write it - that is, when should your code run. You
might want it to run when the form first opens or when a new record is
started or when the user presses a button. Basically, if your form is bound
to a table then you could simply write:

Me!AnyDate = Date()

Where AnyDate is the name of the field. I would not use reserved words
(Date, Name, etc) for field names.
If your form is not bound, or you wanted to update a record other than the
current one then we would need to know which is the primary key so we know
which row to update. In other words give further details about the
structure of tblTest.
Fletcher

Nov 12 '05 #3

P: n/a
I am sorry for the lack of information. The form is bound to the table
tblTest. I have 3 fields within that table which are testid, testname and
testdate. testid is the primary key. The name field will be filled in
through the form. However I have a button on the form, which when clicked I
would like the field testdate to be updated with the current date. That is
why I was asking for the code. When this button is clicked a report is
generated the field is data stamped.

Thanks,

John
"Fletcher Arnold" <fl****@home.com> wrote in message
news:bu**********@sparta.btinternet.com...
"news.btinternet.com" <te*****@btinternet.com> wrote in message
news:bu**********@sparta.btinternet.com...
I have a very simple database. I have information in a form that I would
like to write to a table using some code. The table is called tblTest. The field I would like to write to is called Date. The data which I would like to write is Date(). Please can someone help me with this simple code?

Many Thanks,
John

Normally, there would be no point writing code for this sort of thing. If
your form is bound to the table, then you can simply edit the data using

the form and if you needed, for example, today's date automatically entered in a record then you could use the Date() function as the default value.

If you are certain you need (or want) to write code, then the first thing to consider is where to write it - that is, when should your code run. You
might want it to run when the form first opens or when a new record is
started or when the user presses a button. Basically, if your form is bound to a table then you could simply write:

Me!AnyDate = Date()

Where AnyDate is the name of the field. I would not use reserved words
(Date, Name, etc) for field names.
If your form is not bound, or you wanted to update a record other than the
current one then we would need to know which is the primary key so we know
which row to update. In other words give further details about the
structure of tblTest.
Fletcher


Nov 12 '05 #4

P: n/a
"news.btinternet.com" <te*****@btinternet.com> wrote in message
news:bv**********@sparta.btinternet.com...
I am sorry for the lack of information. The form is bound to the table
tblTest. I have 3 fields within that table which are testid, testname and
testdate. testid is the primary key. The name field will be filled in
through the form. However I have a button on the form, which when clicked I would like the field testdate to be updated with the current date. That is
why I was asking for the code. When this button is clicked a report is
generated the field is data stamped.

Thanks,

John
Then, if AnyDate is the name of the field, all you have to write is:

Me!AnyDate = Date()

But are you sure the user should have to click a button? If you made the
default value for that field the current date, then today's date would be
automatically put in without anyone having to click anything.

I didn't quite get the report bit here: When this button is clicked a report is generated the field is data

stamped.
Fletcher
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.