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

Access Modules

P: n/a
I am trying to find a way to append data from a user into a table using Code
module. Here is an example:
I have a table "SHORTS" and fields "DATE" and "SHORT". I wrote the code
below but access won't recognize the fields. Can some one Help please.
Dim strShorts as Sting
Dim dtShort as Date
dtDhort = Date
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
[SHORTS]![DATE] = dtShort
[SHORTS]![SHORT] = strShorts

Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I'm no programmer but I know that DATE is a reserved word which you should
use as a field name. Maybe that's the problem???

Mark

"Kissi Asiedu" <ki*******@aol.com> wrote in message
news:3s*******************@fe78.usenetserver.com.. .
I am trying to find a way to append data from a user into a table using Code
module. Here is an example:
I have a table "SHORTS" and fields "DATE" and "SHORT". I wrote the code
below but access won't recognize the fields. Can some one Help please.
Dim strShorts as Sting
Dim dtShort as Date
dtDhort = Date
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
[SHORTS]![DATE] = dtShort
[SHORTS]![SHORT] = strShorts


Nov 13 '05 #2

P: n/a
On Sat, 23 Jul 2005 10:25:50 -0400, Kissi Asiedu wrote:
I am trying to find a way to append data from a user into a table using Code
module. Here is an example:
I have a table "SHORTS" and fields "DATE" and "SHORT". I wrote the code
below but access won't recognize the fields. Can some one Help please.
Dim strShorts as Sting
Dim dtShort as Date
dtDhort = Date
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
[SHORTS]![DATE] = dtShort
[SHORTS]![SHORT] = strShorts


Date is a reserved Access/VBA/Jet word and should not be used as a
field name.
Change the field named "Date" to something else, perhaps "SaleDate".

See the Microsoft KnowledgeBase article for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'

How you update the table depends upon other factors.
Where did you place this code? In a form's Code Module, or in an
Application Module?

In a Form module, if [YourDateField] and [Short] are included in the
form's record source, you can use:

(Note that strShorts in your example above is Dimmed as Sting.
It should be String. However, there is no need to Dim any variables.)

[YourDateField] = Date ' Enter the current date into [YourDateField]
[SHORT] = inputbox ("Enter Shorts", "Today's Shorts")

In an Application Module run an Update query (look up Update Query in
Access help) or open the recordset and make the change directly.

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #3

P: n/a

"Kissi Asiedu" <ki*******@aol.com> wrote in message
news:3s*******************@fe78.usenetserver.com.. .
I am trying to find a way to append data from a user into a table using
Code module. Here is an example:
I have a table "SHORTS" and fields "DATE" and "SHORT". I wrote the code
below but access won't recognize the fields. Can some one Help please.
Dim strShorts as Sting
Dim dtShort as Date
dtDhort = Date
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
[SHORTS]![DATE] = dtShort
[SHORTS]![SHORT] = strShorts


You can't just say "set this field in the table to strShort", because it
won't know which record you are talking about: a new one?, the first one? ,
etc. So you have to run an append query or append to a recordset. The first
is easiest and best in this case:

Dim strShorts as string
dim strSQL as string
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
strSQL ="INSERT INTO Shorts ( datefield, short) SELECT Date() , '" &
strShorts & "' ;"
DoCmd.RunSQL (strSQL)

Notice I've changed the field name "date" to "datefield". You can use what
you want, but you shouldn't use special words like "date" as field names,
because they have other meanings to Access and could cause problems.

Do you have a good intro book on VB for Access? If not, it would be a good
investment.
Nov 13 '05 #4

P: n/a
Kissi Asiedu wrote:
I am trying to find a way to append data from a user into a table using Code
module. Here is an example:
I have a table "SHORTS" and fields "DATE" and "SHORT". I wrote the code
below but access won't recognize the fields. Can some one Help please.
Dim strShorts as Sting
Dim dtShort as Date
dtDhort = Date
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
[SHORTS]![DATE] = dtShort
[SHORTS]![SHORT] = strShorts


Where is [SHORTS]![DATE] and [SHORTS]![SHORT] comming from? As noted by
others, if a form, assign it to the name in the form. If a recordset,
you need to edit/assign/update the values
Dim rst As Recordset
set rst = CUrrentdb.openrecordset("Table",dbopendynaset)
rst.findfirst "ShortID = " & 123
rst.edit
rst!Date = dtShort
rst!Short = strShorts
rst.Update
rst.close
set rst = Nothing
or you can create an update query.

Simply specifying the table and field will not do anything.

Nov 13 '05 #5

P: n/a
Thank you guys, you've been of great help.
"Salad" <oi*@vinegar.com> wrote in message
news:2G****************@newsread3.news.pas.earthli nk.net...
Kissi Asiedu wrote:
I am trying to find a way to append data from a user into a table using
Code module. Here is an example:
I have a table "SHORTS" and fields "DATE" and "SHORT". I wrote the code
below but access won't recognize the fields. Can some one Help please.
Dim strShorts as Sting
Dim dtShort as Date
dtDhort = Date
strShorts = inputbox ("Enter Shorts", "Today's Shorts")
[SHORTS]![DATE] = dtShort
[SHORTS]![SHORT] = strShorts


Where is [SHORTS]![DATE] and [SHORTS]![SHORT] comming from? As noted by
others, if a form, assign it to the name in the form. If a recordset, you
need to edit/assign/update the values
Dim rst As Recordset
set rst = CUrrentdb.openrecordset("Table",dbopendynaset)
rst.findfirst "ShortID = " & 123
rst.edit
rst!Date = dtShort
rst!Short = strShorts
rst.Update
rst.close
set rst = Nothing
or you can create an update query.

Simply specifying the table and field will not do anything.


Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.