0

I have created a message box that is a like a reminder and pops up when my switchboard opens on my database.

the message box tells me how many customers havent paid for their order in 25 days. I have put the code into the On Load Section of the switchboard.

However, when i click into my switchboard the code runs instantly which is expected and the message box appears saying "There are x uncompleted payments that have not been paid in 25 days, would you like to see these now" and there is a yes or no button.

But when this box loads and i click yes my switchboard and query opens at the same time and it automatically directs me to the switchboard and not the query that i want to see on my screen. I am aiming to have the main menu open, delay the code for a certain amount of seconds then opens the query if i select yes.

This is the code i have produced.

Public Sub Form_Load()

Dim time1, time2

time1 = Now
time2 = Now + TimeValue("0:00:05")
    Do Until time1 >= time2
        time1 = Now()
    Loop





Dim OS As Integer
OS = DCount("[Paid]", "[OutstandingPayments]", "DateDiff('d', DateOrder, 
Now()) > 25")




If OS = 0 Then

        Exit Sub
            Else


                If MsgBox("There are " & OS & " uncompleted Payments that have not been paid in 25 days" & _
                vbCrLf & vbCrLf & "Would you like to see these now?", _
                vbYesNo, "You Have Uncomplete Payments...") = vbYes Then
                DoCmd.Minimize
                DoCmd.OpenQuery "OutstandingPayments", acNormal

            Else
        Exit Sub
    End If
End If
End Sub

Basically what this code does is just delay the code being produced but i thought the switchboard could open showing the screen then the code would run and then display my message box.

is there a way i can be able to open switchboard on load, have it loaded then for my code to run to display my message box.

Gif attached to illustrate problem https://gyazo.com/94f7e56cbe9220673d10a810e5282dda

Thank you.

Cbrady
  • 93
  • 1
  • 2
  • 7

1 Answers1

1

You can use the Form.Timer property to set a timer, and execute the code after that timer.

Private Sub Form_Load()
    Me.TimerInterval = 5000 '5000 milliseconds
    'Do other stuff
End Sub

Private Sub Form_Timer()
    Me.TimerInterval = 0 'Disable timer from running again
    'Do stuff
End Sub

Also, if you're going to delay using a while loop, fill it with DoEvents + a sleep function (like this one) to prevent it from locking down your program.

Erik A
  • 31,639
  • 12
  • 42
  • 67
  • I entered that in and it says "Compile Error, Method or Data Member not Found" – Cbrady Feb 07 '18 at 21:18
  • ah, sorry, fixed it now – Erik A Feb 07 '18 at 21:19
  • https://gyazo.com/954b87cfc5c17267077bb512ccb0484f Couldnt post code here as it was too long but I have added this in but the TimeInterval doesnt seem to execute, the code executes instantly without waiting 5 seconds – Cbrady Feb 07 '18 at 21:24
  • Have you added it in the form_timer section, and not form_load? – Erik A Feb 07 '18 at 21:25
  • I have figured it out, i needed to put `Me.TimerInterval =5000` at the beginning at the `Me.TimerInterval=0` in the Form_Timer() along with the rest of my code for the msgbox. thanks for your help! – Cbrady Feb 07 '18 at 21:27