5 Replies - 6992 Views - Last Post: 30 July 2009 - 07:54 AM Rate Topic: -----

#1 Timer1.interval  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 09

How to capture date and time

Post icon  Posted 29 July 2009 - 07:12 AM

I'm working on a database program for a bookshop and I want to add the date and the time a new stock is added to the database but don't know how to go about it. So far I'v been able to display a live time and current date but I don't know how to insert them into my database. Below is the code I use to add new data to my ms access database


If Text1.Text = "" And Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" Then
msg = MsgBox("All fields are required!", vbInformation + vbOKOnly)
Data1.Recordset.MoveLast
Command9.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command5.Enabled = False
Command4.Enabled = False
Command7.Enabled = False
Command11.Enabled = False
Text1.SetFocus
Else
Data1.Recordset.AddNew
Data1.Recordset.Update
msg = MsgBox("Record added to database!", vbInformation)
End If
Data1.Recordset.MovePrevious
Command2.Enabled = True
Command3.Enabled = True
Command5.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command11.Enabled = True
Command9.Enabled = False

Prompt responce will be appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: How to capture date and time

#2 DCunningham  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 19-May 09

Re: How to capture date and time

Posted 29 July 2009 - 07:15 AM

If I'm understanding right, you already have a timer set that displays the current time in a label or something? Well if this is so it could be feasible to just send the 'timer's display label.TEXT' property to the database when you are updating. Or set a variable that catches that same text property and then pass it via the variable. There is one question though, what is the data type you have set for this 'date/time' field in your database?

This post has been edited by DCunningham: 29 July 2009 - 07:17 AM

Was This Post Helpful? 0
  • +
  • -

#3 MajorWalrus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 115
  • Joined: 22-April 09

Re: How to capture date and time

Posted 29 July 2009 - 08:26 AM

If you're talking about adding the system data and time you can do it with the "Now" statement like this:

Dim myDate As Date
Dim myTime As Date

myDate = DateValue(Now)
myTime = TimeValue(Now)


Be warned that you might need to format the result to get what you want. As in, you might have to change 01/01/2000 to January 1, 2000.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#4 Timer1.interval  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 09

Re: How to capture date and time

Posted 30 July 2009 - 05:38 AM

View PostMajorWalrus, on 29 Jul, 2009 - 07:26 AM, said:

If you're talking about adding the system data and time you can do it with the "Now" statement like this:

Dim myDate As Date
Dim myTime As Date

myDate = DateValue(Now)
myTime = TimeValue(Now)


Be warned that you might need to format the result to get what you want. As in, you might have to change 01/01/2000 to January 1, 2000.

Good luck!



I already have two fields Time and Date in the database but the problem is capturing the time and date the stock is saved into those fields. The normal thing I know is that the text boxes diplaying the date and time are supposed to get thier sources form the data control tool I'm using, so that gives me the problem because if my text boxes are getting thier data from the db then there seem to be noway I can capture the live time and current date into them
Was This Post Helpful? 0
  • +
  • -

#5 Timer1.interval  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 09

Re: How to capture date and time

Posted 30 July 2009 - 05:46 AM

View PostDCunningham, on 29 Jul, 2009 - 06:15 AM, said:

If I'm understanding right, you already have a timer set that displays the current time in a label or something? Well if this is so it could be feasible to just send the 'timer's display label.TEXT' property to the database when you are updating. Or set a variable that catches that same text property and then pass it via the variable. There is one question though, what is the data type you have set for this 'date/time' field in your database?





I already have two fields Time and Date in the database but the problem is capturing the time and date the stock is saved into those fields. The normal thing I know is that the text boxes diplaying the date and time are supposed to get thier sources form the data control tool I'm using, so that gives me the problem because if my text boxes are getting thier data from the db then there seem to be noway I can capture the live time and current date into them
Was This Post Helpful? 0
  • +
  • -

#6 DCunningham  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 19-May 09

Re: How to capture date and time

Posted 30 July 2009 - 07:54 AM

Well you could have two separate functions for the database controls.. say one set that you use to enter in new data and then another that displays the data that has been entered. It's during the data entry where you can send the 'System.DateTime.Now()' information, update the date and time fields with this and then as a separate entity entirely display the database fields that hold that info. Hope this helps.

D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1