Adding 30 mins onto a 24hr time & displaying print details when form revisited

Posted on 2003-03-25
Medium Priority
Last Modified: 2012-05-04
How do I add 30 mins onto 24hr time?

The following code works to display information used by print statements, but whenever I go to a different form and return to this form the printed information doesn't appear, but works ok if I re-start the program. Do you have any suggestions?
Private Sub Form_Load()

'Get Todays date
Dim TodayDate As Date
TodayDate = Format(Date, "dd/mm/yyyy")

'Print the details on the form
frmMaresToBeScanned.ForeColor = vbWhite
frmMaresToBeScanned.Print ""
frmMaresToBeScanned.Print ""
frmMaresToBeScanned.Print ""
frmMaresToBeScanned.Print ""
frmMaresToBeScanned.Print ""

frmMaresToBeScanned.Print Tab(40); "Todays Date:", TodayDate
frmMaresToBeScanned.Print Tab(40); "****************"
frmMaresToBeScanned.Print ""
frmMaresToBeScanned.Print ""
frmMaresToBeScanned.Print Tab(40); "Scan Number"; Tab(63); "Vet Number"; Tab(85); "Mare Number"
frmMaresToBeScanned.Print Tab(40); "***************"; Tab(63); "*************"; Tab(85); "****************"
frmMaresToBeScanned.Print ""

' Search and display mares to be scanned today
Dim ScanNo As Integer
Dim VetNo As Integer
Dim MareNo As Integer

Do Until frmMainMenu.datScan.Recordset.EOF
    If (frmMainMenu.datScan.Recordset.Fields("DateOfScan") = TodayDate) Then
        ScanNo = frmMainMenu.txtScanNo.Text
        VetNo = frmMainMenu.txtVetNo.Text
        MareNo = frmMainMenu.txtMareNo.Text
        frmMaresToBeScanned.Print Tab(40); ScanNo; Tab(63); VetNo; Tab(85); MareNo
    End If
End Sub
Question by:Lucy168
LVL 55

Expert Comment

by:Ryan Chong
ID: 8201914
Try DateAdd function..
LVL 43

Accepted Solution

TimCottee earned 120 total points
ID: 8201965
Hi Lucy168,

Indeed, dateadd is one part:

NewTime = DateAdd("n",30,OldTime)

You also need to set the .autoredraw property of the form to true before using Print on the form. This will preserve your print statements when you move to another form and back again.


Brainbench MVP for Visual Basic

Experts-Exchange Advisory Board Member

Author Comment

ID: 8205302
This works but I cant get the time to be in (hh/mm) instead it is in (hh/mm/ss). How do I get rid of the seconds?

I also Can’t get it to leave a 1hr break, between 13:00 and 14:00, instead if just executes the first If statement: If (Not NewTime = DateAdd("n", 30, BeforeDinnerTime)) Then
OldTime = NewTime
NewTime = DateAdd("n", 30, OldTime)
Time = NewTime

The code used is shown below:

Dim NewTime As Date
Dim OldTime As Date
NewTime = "08:30"

Dim BeforeDinnerTime As Date
Dim AfterDinnerTime As Date
BeforeDinnerTime = "12:30"
AfterDinnerTime = "13:30"

Dim Time As String
Dim MareStatusNo As Integer
Dim MareNo As Integer
Dim MareFieldNo As String
Dim StallionNo As Integer
Dim FirstDateServed As String
Dim ArrivalDate As Date
Dim MareFinishedBeingServed As String
Dim MareNotToBeServiced As String

Do Until frmMainMenu.datProcessStatus.Recordset.EOF
    If (Not frmMainMenu.datProcessStatus.Recordset.Fields("ArrivalDate") = "") And (frmMainMenu.datProcessStatus.Recordset.Fields("MareFinishedBeingServed") = "No") Then
         If (Not NewTime = DateAdd("n", 30, BeforeDinnerTime)) Then
            OldTime = NewTime
            NewTime = DateAdd("n", 30, OldTime)
            Time = NewTime
        ElseIf (NewTime = DateAdd("n", 30, BeforeDinnerTime)) Then
            NewTime = DateAdd("n", 30, AfterDinnerTime)
            Time = NewTime
        End If
            MareStatusNo = frmMainMenu.txtProcessStatusNo.Text
            MareNo = frmMainMenu.txtMareNum.Text
            MareFieldNo = frmMainMenu.txtMareFieldNo.Text
            StallionNo = frmMainMenu.txtStallionNo.Text
            FirstDateServed = frmMainMenu.txtFDServed.Text
            frmMaresToBeServiced.Print Tab(40); Time; Tab(47); MareStatusNo; Tab(64); MareNo; Tab(73); MareFieldNo; Tab(88); StallionNo; Tab(101); FirstDateServed;
    End If

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

621 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