?
Solved

sql INSERT INTO problem with using date() function

Posted on 2005-03-30
8
Medium Priority
?
207 Views
Last Modified: 2010-05-02
I am having a problem using an INSERT INTO statement with the date() and environ("username") function in vb.

TXT_DATE = DATE()
TXT_COM_MOD = Environ("username")

str_sql = _
"INSERT INTO Comments (ID, DATE, COM_MOD) VALUES (" & CMB_ID & "," & TXT_DATE & TXT_COM_MOD &")"

DoCmd.RunSQL str_sql

the ID is being pulled fine from a combo box

the DATE is being pulled from a text box on a form where the date is correct but when it is written to the table it is showing up as 12/30/1899 and when i click on the date in the table the date changes to a time showing 12:00:004 am
and when i deselect the field it returns to 12/30/1899

and when the sql statment runs it brings up an enter parameter value dialog box for input on the user id

If anyone knows what is causing these problems your help would be greatly appreciated
0
Comment
Question by:CanIJay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 280 total points
ID: 13663817
Try delineating your dates with pound signs.

"INSERT INTO Comments (ID, DATE, COM_MOD) VALUES (" & CMB_ID & ", #" & TXT_DATE & "#, " & TXT_COM_MOD & ")"

Also, you werre missing a comma between txt_date and txt_com_mod

Hope this helps.
-Jim
0
 

Author Comment

by:CanIJay
ID: 13663830
I tried to edit my comment but that was just a typo on the forum part, in my program i have the comma
0
 

Author Comment

by:CanIJay
ID: 13663849
you were correct on the date part, thanks.
do you have any idea why the com_mod from the environ is asking for parameter value
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 66

Expert Comment

by:Jim Horn
ID: 13663862
Nope.  Try msgbox environ("username") to make sure it's pulling the user's network ID correctly.  If not, then there's a .dll call you can use.
0
 
LVL 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 220 total points
ID: 13663894
try:

str_sql = "INSERT INTO Comments (ID, DATE, COM_MOD) VALUES (" & CMB_ID & ", Date() , '" & replace(TXT_COM_MOD,"'","''") & "' )"
0
 

Author Comment

by:CanIJay
ID: 13663908
I'm pretty sure it's pulling the id fine because on the form the correct id is showing up in the text box, and it also shows it in the enter parameters dialog box.
0
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 280 total points
ID: 13663970
(Slight oversight)  since this is a text field, deliate it with strings (ryancys has it in his above post)

"INSERT INTO Comments (ID, DATE, COM_MOD) VALUES (" & CMB_ID & ", #" & TXT_DATE & "#, '" & TXT_COM_MOD & "')"
0
 

Author Comment

by:CanIJay
ID: 13664081
Awsome! thanks for all your help guys, it works wonderful now
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question