473,397 Members | 2,099 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,397 software developers and data experts.

Access Modules

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
5 1812
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
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

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

Similar topics

28
by: deko | last post by:
After doing a lot of vba work, I've noticed the size of my mdb has grown, even though no data or objects have been added. I've read that the following procedure will remedy this and improve...
4
by: rufus | last post by:
Hi, On the project I am working on we need to encapsulate all data and business logic in an activex dll. My question is: How do I do this? How can I access the form objects ie text boxes,...
55
by: AnandaSim | last post by:
I just had a google through this NG but have not seen mention of Erik Rucker's blog entry and the new Jet: http://blogs.msdn.com/access/archive/2005/10/05/477549.aspx mentioned by Mike...
5
by: jqpdev | last post by:
Hello all... I'm coming from a Borland Delphi background. Delphi has a specific component called a Data Module. In the designer the Data Module behaves like a windows form. A developer can...
13
by: Robin Haswell | last post by:
Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules...
1
by: nandar | last post by:
Hi All, I am involved in migratinig one of the MS Access Project to ASP.Net and SQL Server 2000. My question here is that how Modules and Class Modules can be taken care in ASP.Net. To some...
0
by: nandar | last post by:
Hi All, I am involved in migratinig one of the MS Access Project to ASP.Net and SQL Server 2000. My question here is that how Modules and Class Modules (MS Access) can be taken care in ASP.Net. To...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
3
by: Roy Tong | last post by:
I maintain a shared database on Access 97. I've just tried converting a test copy of the database to 2003 and it appeared to work OK. That is I got no error messages. However then I look at my...
4
by: howard.canaway | last post by:
I have always wondered about the specification page in the Access Help files. It reads Microsoft Access database (.mdb) file size 2 gigabytes. However, because your database can include linked...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.