• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

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

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
rehman123
Asked:
rehman123
  • 4
  • 4
  • 3
  • +3
1 Solution
 
black_helpCommented:
Why dont you just add it like this:
cn.execute “Insert into emp (hiredate) values (‘” & now() &”’ )
?
0
 
diegojserranoCommented:
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
 
rehman123Author Commented:
it is giving syntex error
Expected End of statement.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
diegojserranoCommented:
what line is giving that error?
post the code
0
 
black_helpCommented:
cn.execute "Insert into emp (hiredate) values ('" & date.caption & " " & lbl_time.caption & "')"
0
 
diegojserranoCommented:
hey, black_help is rigth check out  ' and "
if you only copy and paste from here you can have different characters
0
 
rehman123Author Commented:
and with now( )  function i got this error ..
Number of query value and destination fields are  not the  same...
0
 
shutuplonnieCommented:
then your sql statement isn't the same as your database structure..
0
 
shutuplonnieCommented:
How many fields in the database? and what are they?
0
 
Ryan ChongCommented:
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
 
Ryan ChongCommented:
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
 
AzraSoundCommented:
Access requires that you enclose date/time fields with pound(#) signs, so:

cn.execute "Insert into emp (hiredate) values (#" & date.caption) & "#) "
0
 
rehman123Author Commented:
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
 
black_helpCommented:
cn.execute "Insert into emp (hiredate) values (#" & date.caption & " " & lbl_time.caption & "#) "
0
 
black_helpCommented:
Does it work now?
0
 
Ryan ChongCommented:
>>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
 
AzraSoundCommented:
Good job appending MY answer...
0
 
rehman123Author Commented:
thanks black
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now