473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Update a Table

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
4 2380
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
1
by: adithi | last post by:
My Table Structure is: Table A Table B Table C colA -PK Col B-PK Col C-PK Col B-FK ...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.