Access 2003 - Date Insertion

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am building a acces tool to track sepsis infections. There are several
date variables. I don't know how to include a check box that would
automatically insert the registration date into all of the other date fields
if they are the same.

I also need help in calculating minuetues across 24 hour time period.

Thanks to anyone that can help!!!
 
Andy:

Are all these dates fields in the same table or query to which the form is
bound? If so then you just need to assign the value of the registration date
to the others with a few line of code.

Dim varDate as Variant

varDate = Me.[RegistationDate]

Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on

You can put this in the AfterUpdate event procedure of the RegistrationDate
control if you want the others to automatically be given the same date as
their defaults when the registration date is entered; or you can put it in
the Click event procedure of a button on the form. The former is probably
not a good idea as a user could enter the other date(s) first and then go
back to the registration date; this may be unlikely but its theoretically
possible in a form. If you do use the AfterUpdate event procedure you might
want to get user confirmation:

Const conMESSAGE = "Use this date for x, y and z dates?"
Dim varDate as Variant

varDate = Me.[RegistationDate]

If MsgBox(conMESSAGE, vbYesNo + vbQuestion, "Repeat date?" = vbYes Then
Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on
End If

If you use a check box then you first have to see if the registration date
is already entered, and if so assign its date to the other controls. So the
code for the check box's AfterUpdate event procedure would be like this:

Dim varDate as Variant

varDate = Me.[RegistationDate]

If Not IsNull(vardate) Then
If Me.[YourCheckBoxName] Then
Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on
Else
Me.[SomeOtherDate] = Null
Me.[YetAnotherDate] = Null
' and so on
End If
End If

This would assign the registration date to the other dates if one has been
entered; if no registration date has yet been entered it would clear any
values in the other dates by setting them to Null. The code for the
AfterUpdate event of the RegistrationDate would now assign the values if the
check box had been checked before any dates were entered:

Dim varDate as Variant

varDate = Me.[RegistationDate]

If Not IsNull(vardate) Then
If Me.[YourCheckBoxName] Then
Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on
Else
Me.[SomeOtherDate] = Null
Me.[YetAnotherDate] = Null
' and so on
End If
End If

You'll see that this is the same as the check box's code. The duplication
could be avoided by putting the code in a function in the form's module and
calling the function as the event property of both controls, but it will work
the same either way. Modularising the code in a function is just more
elegant.

The check box must be unbound of course and you'll probably want to reset it
to False (unchecked) in the form's Current event procedure:

Me.YourCheckBoxName = False

As regards calculating in minutes take a look at the DateDiff and DateAdd
functions. These have an Interval argument, for which the setting for
minutes is "n" ("m" is used for months).

Ken Sheridan
Stafford, England
 
I am building a acces tool to track sepsis infections. There are several
date variables. I don't know how to include a check box that would
automatically insert the registration date into all of the other date fields
if they are the same.

You could put code into the AfterUpdate event of the checkbox control
like:

Private Sub chkAllTimes_AfterUpdate()
If Me!chkAllTimes Then ' did the user check the box?
Me!txtThisTime = NZ(Me!txtThisTime, Me!txtRegistrationDate)
Me!txtThatTime = NZ(Me!txtThisTime, Me!txtRegistrationDate)
<etc>
End If
End Sub

The NZ() function ensures that only *blank* controls will be
overwritten; someone might have entered some data and then clicked the
checkbox.
I also need help in calculating minuetues across 24 hour time period.

An Access date/time value is stored as a simple number - a count of
days and fractions of a day (times) since midnight, December 30, 1899.
As such it doesn't explicitly contain minutes and hours. If you have
two date/time values you can use the DateDiff() function to calculate
the minutes (or seconds, or years, or any other time unit) between
them:

DateDiff("n", [CheckIn], [CheckOut])

"n" means "miNutes"; "m" is "Months".


John W. Vinson[MVP]
 
THANK YOU SOO MUCH!!!!! I would be so limited if I didn't get help from this
discussion groups. I greatly appreciate you taking the time to help me!!!
--
Thanks,
Andy


Ken Sheridan said:
Andy:

Are all these dates fields in the same table or query to which the form is
bound? If so then you just need to assign the value of the registration date
to the others with a few line of code.

Dim varDate as Variant

varDate = Me.[RegistationDate]

Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on

You can put this in the AfterUpdate event procedure of the RegistrationDate
control if you want the others to automatically be given the same date as
their defaults when the registration date is entered; or you can put it in
the Click event procedure of a button on the form. The former is probably
not a good idea as a user could enter the other date(s) first and then go
back to the registration date; this may be unlikely but its theoretically
possible in a form. If you do use the AfterUpdate event procedure you might
want to get user confirmation:

Const conMESSAGE = "Use this date for x, y and z dates?"
Dim varDate as Variant

varDate = Me.[RegistationDate]

If MsgBox(conMESSAGE, vbYesNo + vbQuestion, "Repeat date?" = vbYes Then
Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on
End If

If you use a check box then you first have to see if the registration date
is already entered, and if so assign its date to the other controls. So the
code for the check box's AfterUpdate event procedure would be like this:

Dim varDate as Variant

varDate = Me.[RegistationDate]

If Not IsNull(vardate) Then
If Me.[YourCheckBoxName] Then
Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on
Else
Me.[SomeOtherDate] = Null
Me.[YetAnotherDate] = Null
' and so on
End If
End If

This would assign the registration date to the other dates if one has been
entered; if no registration date has yet been entered it would clear any
values in the other dates by setting them to Null. The code for the
AfterUpdate event of the RegistrationDate would now assign the values if the
check box had been checked before any dates were entered:

Dim varDate as Variant

varDate = Me.[RegistationDate]

If Not IsNull(vardate) Then
If Me.[YourCheckBoxName] Then
Me.[SomeOtherDate] = varDate
Me.[YetAnotherDate] = varDate
' and so on
Else
Me.[SomeOtherDate] = Null
Me.[YetAnotherDate] = Null
' and so on
End If
End If

You'll see that this is the same as the check box's code. The duplication
could be avoided by putting the code in a function in the form's module and
calling the function as the event property of both controls, but it will work
the same either way. Modularising the code in a function is just more
elegant.

The check box must be unbound of course and you'll probably want to reset it
to False (unchecked) in the form's Current event procedure:

Me.YourCheckBoxName = False

As regards calculating in minutes take a look at the DateDiff and DateAdd
functions. These have an Interval argument, for which the setting for
minutes is "n" ("m" is used for months).

Ken Sheridan
Stafford, England
 
Thank you as well!!! Again, I really appreciate the time people take to
answer questions on-line.


--
Thanks,
Andy


John Vinson said:
I am building a acces tool to track sepsis infections. There are several
date variables. I don't know how to include a check box that would
automatically insert the registration date into all of the other date fields
if they are the same.

You could put code into the AfterUpdate event of the checkbox control
like:

Private Sub chkAllTimes_AfterUpdate()
If Me!chkAllTimes Then ' did the user check the box?
Me!txtThisTime = NZ(Me!txtThisTime, Me!txtRegistrationDate)
Me!txtThatTime = NZ(Me!txtThisTime, Me!txtRegistrationDate)
<etc>
End If
End Sub

The NZ() function ensures that only *blank* controls will be
overwritten; someone might have entered some data and then clicked the
checkbox.
I also need help in calculating minuetues across 24 hour time period.

An Access date/time value is stored as a simple number - a count of
days and fractions of a day (times) since midnight, December 30, 1899.
As such it doesn't explicitly contain minutes and hours. If you have
two date/time values you can use the DateDiff() function to calculate
the minutes (or seconds, or years, or any other time unit) between
them:

DateDiff("n", [CheckIn], [CheckOut])

"n" means "miNutes"; "m" is "Months".


John W. Vinson[MVP]
 
i need to make check box to be changed to date that i'm checked on the box.
did it's same ways with what you wrote
--
access for life


Andy said:
Thank you as well!!! Again, I really appreciate the time people take to
answer questions on-line.


--
Thanks,
Andy


John Vinson said:
I am building a acces tool to track sepsis infections. There are several
date variables. I don't know how to include a check box that would
automatically insert the registration date into all of the other date fields
if they are the same.

You could put code into the AfterUpdate event of the checkbox control
like:

Private Sub chkAllTimes_AfterUpdate()
If Me!chkAllTimes Then ' did the user check the box?
Me!txtThisTime = NZ(Me!txtThisTime, Me!txtRegistrationDate)
Me!txtThatTime = NZ(Me!txtThisTime, Me!txtRegistrationDate)
<etc>
End If
End Sub

The NZ() function ensures that only *blank* controls will be
overwritten; someone might have entered some data and then clicked the
checkbox.
I also need help in calculating minuetues across 24 hour time period.

An Access date/time value is stored as a simple number - a count of
days and fractions of a day (times) since midnight, December 30, 1899.
As such it doesn't explicitly contain minutes and hours. If you have
two date/time values you can use the DateDiff() function to calculate
the minutes (or seconds, or years, or any other time unit) between
them:

DateDiff("n", [CheckIn], [CheckOut])

"n" means "miNutes"; "m" is "Months".


John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top