Code Problem (1 Viewer)

konaan1

Registered User.
Local time
Today, 16:06
Joined
Dec 7, 2011
Messages
15
Can anyone please help me make the following statement work?


SystemTime = CInt(Format(Time, "HHnn"))
If SystemTime < 700 Then
MsgBox ("Please wait until after 7:30 AM to receive latest updates, you can still view old data until that time.")
GoTo Allowed
End If


If SystemTime > 730 And SystemTime < 745 Then
InputBox("Password") = "Test"
Else
MsgBox ("Please wait until after 7:30 AM to get back into the system.")
DoCmd.CloseDatabase
End If

Allowed:

End Sub
 

konaan1

Registered User.
Local time
Today, 16:06
Joined
Dec 7, 2011
Messages
15
the problem is with the 2nd if statement
 

nanscombe

Registered User.
Local time
Today, 21:06
Joined
Nov 12, 2011
Messages
1,082
I've tidied the code up with a Select Case statement, have a try with this:

Code:
Public Sub timeTest()
Dim strPassword As String
SystemTime = Format(Time, "hh:nn")

Select Case SystemTime
Case "00:00" To "07:29"
    MsgBox ("Please wait until after 7:30 AM to receive latest updates, you can still view old data until that time.")
    
Case "07:30" To "07:45"
    strPassword = "Please wait until after 7:30 AM to get back into the system." & vbCrLf & vbCrLf
    strPassword = strPassword & "Or enter the Password"
    
    strPassword = InputBox(strPassword, "Update in  progress", "")
    
    If LCase(strPassword) <> "test" Then
        MsgBox ("Exiting database. Please try again after 7:45")
        DoCmd.CloseDatabase
    End If
    
Case Else
    'Do Nowt
End Select
End Sub
 

konaan1

Registered User.
Local time
Today, 16:06
Joined
Dec 7, 2011
Messages
15
Thanks nanscombe, I continued to play with it while I waited and this seems to work.

Private Sub Form_Load()
DoCmd.Maximize

SystemTime = CInt(Format(Time, "HHnn"))
If SystemTime > 255 And SystemTime < 300 Then
MsgBox ("Please wait until after 7:30 AM to receive latest updates, you can still view old data until that time.")
GoTo Allowed
End If

If SystemTime > 301 And SystemTime < 310 Then
MsgBox ("Time to update!")
ElseIf InputBox("Enter Password") = "Test" Then
GoTo Allowed
Else
MsgBox ("Please wait until after 7:30 AM to get back into the system.")
DoCmd.CloseDatabase
End If

Allowed:
End Sub


nanscombe,

***I tried yours and had similar results.*** For some reason the 1st string is being ignored regardless of the time and it goes directly to the second string.
 

nanscombe

Registered User.
Local time
Today, 21:06
Joined
Nov 12, 2011
Messages
1,082
Eh? 1st string & 2nd string? I'm not sure what you mean.

Anyway, I think the logic below might work a bit better as it will only prompt for a password during required time frame.

Code:
Private Sub Form_Load()
DoCmd.Maximize

SystemTime = CInt(Format(Time, "HHnn"))

If SystemTime > 255 And SystemTime < 300 Then
MsgBox ("Please wait until after 7:30 AM to receive latest updates, you can still view old data until that time.")
GoTo Allowed
End If

If SystemTime > 301 And SystemTime < 310 Then

  MsgBox ("Time to update!")

  If InputBox("Enter Password") = "Test" Then
    GoTo Allowed
  Else
    MsgBox ("Please wait until after 7:30 AM to get back into the system.")
    DoCmd.CloseDatabase
  End If

End If

Allowed:
End Sub
 

konaan1

Registered User.
Local time
Today, 16:06
Joined
Dec 7, 2011
Messages
15
The problem I am still having is that the 1st if statement is being ignored and is asking for the password regardless of the time frame specified in the 2nd if statement.
 

nanscombe

Registered User.
Local time
Today, 21:06
Joined
Nov 12, 2011
Messages
1,082
If it's between 2:55 and 3:00 (In the morning? Not 1455 and 1500?) then run this bit of code:

Code:
If SystemTime > 255 And SystemTime < 300 Then
MsgBox ("Please wait until after 7:30 AM to receive latest updates, you can still view old data until that time.")
GoTo Allowed
End If


If it's between 03:01 and 03:10 then run this bit of code:

Code:
If SystemTime > 301 And SystemTime < 310 Then
MsgBox ("Time to update!")


Any other time run this code:

Code:
ElseIf InputBox("Enter Password") = "Test" Then
GoTo Allowed
Else
MsgBox ("Please wait until after 7:30 AM to get back into the system.")
DoCmd.CloseDatabase
End If


Which is why I switch the logic in my other post.

If it's between 02:55 and 03:00 then run this bit of code:

Code:
If SystemTime > 255 And SystemTime < 300 Then
MsgBox ("Please wait until after 7:30 AM to receive latest updates, you can still view old data until that time.")
GoTo Allowed
End If

ONLY if it's between 03:01 and 03:10 run this code:

Code:
If SystemTime > 301 And SystemTime < 310 Then

  MsgBox ("Time to update!")

  If InputBox("Enter Password") = "Test" Then
    GoTo Allowed
  Else
    MsgBox ("Please wait until after 7:30 AM to get back into the system.")
    DoCmd.CloseDatabase
  End If

End If

At any other time jump straight over both of the If statements.
 

Users who are viewing this thread

Top Bottom