Solved

How to store  date +time in access database  from VB6.

Posted on 2004-04-27
18
691 Views
Last Modified: 2008-03-10
Hi
In my application I am displaying date and time and want to store both in date field of access  database .
i.e . in my current  VB application  I am entering date like this.
cn.execute “Insert into emp (hiredate) values (‘” & date.caption) & “ ‘)

I have one label and I am assigning value to  it using  timer  so   label.cation display  current time in my application
I want to add this  time value  in   horedate field  of emp and  so when I wrote  like
 
cn.execute “Insert into emp (hiredate) values (‘” & date.caption) & “ ‘+ ‘”&lbl_time.caption)&”’ )
it gives me  error invalid  data time ..

format Hiredate field in access database is of  general date  ..

Regards
0
Comment
Question by:rehman123
  • 4
  • 4
  • 3
  • +3
18 Comments
 

Expert Comment

by:black_help
ID: 10930642
Why dont you just add it like this:
cn.execute “Insert into emp (hiredate) values (‘” & now() &”’ )
?
0
 
LVL 3

Expert Comment

by:diegojserrano
ID: 10930704
try
cn.execute “Insert into emp (hiredate) values (‘" & date.caption & " " &lbl_time.caption & "')"
if it doesn't work then msgbox “Insert into emp (hiredate) values (‘" & date.caption & " " &lbl_time.caption & "')" and post here exactly what you see.
0
 

Author Comment

by:rehman123
ID: 10931052
it is giving syntex error
Expected End of statement.
0
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 
LVL 3

Expert Comment

by:diegojserrano
ID: 10931078
what line is giving that error?
post the code
0
 

Expert Comment

by:black_help
ID: 10931140
cn.execute "Insert into emp (hiredate) values ('" & date.caption & " " & lbl_time.caption & "')"
0
 
LVL 3

Expert Comment

by:diegojserrano
ID: 10931164
hey, black_help is rigth check out  ' and "
if you only copy and paste from here you can have different characters
0
 

Author Comment

by:rehman123
ID: 10931165
and with now( )  function i got this error ..
Number of query value and destination fields are  not the  same...
0
 

Expert Comment

by:shutuplonnie
ID: 10931178
then your sql statement isn't the same as your database structure..
0
 

Expert Comment

by:shutuplonnie
ID: 10931203
How many fields in the database? and what are they?
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 10931230
Try:

cn.execute “Insert into emp (hiredate) values (Now())

?

or even simply, you can directly set the Default Now value into a Field, Try open the table in Design View, then select the hiredate field, try go to it's Default Property, enter =Now(), then try save the table. And execute your Statement again, like:

cn.execute “Insert into emp (employeeName, age) values ('ABC', 25)

etc

Hope this helps
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 10931272
Missing to close the statement, should be:

cn.execute “Insert into emp (hiredate) values (Now())"

and

cn.execute “Insert into emp (employeeName, age) values ('ABC', 25)"
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 10933370
Access requires that you enclose date/time fields with pound(#) signs, so:

cn.execute "Insert into emp (hiredate) values (#" & date.caption) & "#) "
0
 

Author Comment

by:rehman123
ID: 10936206
shutuplonnie and black_help
I tried your  lines  but it gives me error  end of  statement , i copied and pasted from here . u pls check it  out ..
and azrasound your  syntex worked  but i want to store date and time  not just date ..  thanks.
0
 

Accepted Solution

by:
black_help earned 500 total points
ID: 10937219
cn.execute "Insert into emp (hiredate) values (#" & date.caption & " " & lbl_time.caption & "#) "
0
 

Expert Comment

by:black_help
ID: 10958657
Does it work now?
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 10960785
>>cn.execute “Insert into emp (hiredate) values (Now())"
Is that not working or what.. ? or you need the same Date/Time as what you had displayed? If yes, just try others suggestion, their suggestion Should works.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 10970609
Good job appending MY answer...
0
 

Author Comment

by:rehman123
ID: 10970611
thanks black
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from 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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

815 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now