Solved

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

Posted on 2004-04-27
18
687 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 49

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 49

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 49

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 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

27 Experts available now in Live!

Get 1:1 Help Now