Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

sql INSERT INTO problem with using date() function

Posted on 2005-03-30
8
Medium Priority
?
214 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 55

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

571 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