grobermatic
Technical User
Hi all,
Can you Loop back to a DO from within an IF statement?
I'm getting the "Loop without Do" compile error at in the following code at the red highlighted point...
Code Follows :
================= CODE START ===========================
Option Compare Database
Option Explicit
Sub RunApp()
Dim strRunResponse As String
Dim strResponse As String
Dim strSQL As String
strRunResponse = MsgBox("Do you want to run Suspense Reader?", vbQuestion + vbYesNo, "Run Application?")
If strRunResponse = 6 Then 'YES to RUN
strResponse = MsgBox("Do you want to save a copy of the last suspense reading?" & vbCrLf & vbCrLf & _
"THIS WILL OVERWRITE ALL PREVIOUSLY SAVED READINGS", vbQuestion + vbYesNo, "Save?")
If strResponse = 6 Then 'YES to SAVE
DoCmd.SetWarnings False 'Run queries to save last reading
DoCmd.OpenQuery "qrySaveLastReading"
DoCmd.OpenQuery "qrySuspenseData_DELETE"
DoCmd.SetWarnings True
Else
DoCmd.SetWarnings False 'Run queries to delete data currently in table
DoCmd.OpenQuery "qrySuspenseData_DELETE"
DoCmd.SetWarnings True
End If
MsgBox "The system will now try to connect to the Commercial Sysytem" & vbCrLf & vbCrLf & _
"Please ensure that EXTRA! Mainframe is open and that you are logged in to the Commercial System ", _
vbOKOnly, "Connecting to EXTRA!..."
'========== CONNECT LOOP ===============
Do 'Connect Loop
Extra_Connect 'Run Extra_Connect procedure
If System = "EXTRA! Personal Client" And Sess0 = "Ventura" Then 'Connected
MsgBox "Connected to :" & vbCrLf & vbCrLf & _
"System: " & System & vbCrLf & _
"Session: " & Sess0 & vbCrLf & vbCrLf & _
"Press Ok to continue...", vbOKOnly, "Connected"
Exit Do 'Exit loop if connected
Else 'Not Connected
strResponse = MsgBox("The database was unable to connect to EXTRA! Mainframe" & vbCrLf & vbCrLf & _
"Please check that EXTRA! is running and that you are logged on to the Commercial System " & _
"using your CTRF code." & vbCrLf & vbCrLf & _
"Press Ok to try again or Cancel to stop trying", vbCritical + vbOKCancel, "Unable to Connect!")
If strResponse = 1 Then
Loop 'Keep trying to connect until user clicks Cancel
Else
MsgBox "If you have been unable to connect to EXTRA!, " & _
"Please contact Craig Lomas (Xt: 99999 or email: me.name@mycompany.com) to get your system checked." & vbCrLf & vbCrLf & _
"The database will now close.", vbInformation, "Commercial Suspense Reader"
Application.Quit
Exit Do
End If
End If
'=========== END OF CONNECT LOOP ==================
MsgBox "The database will now try to connect to Commercial Suspense (SUS1)" & _
"Please ensure that the screen is clean (No Half Edited Accounts)", vbOKOnly, "Connecting to SUS1..."
Do 'Loop to connect to suspense
Goto_SUS1
If ExCap("SUSName") = "TRF Payment Suspense" Then
MsgBox "Connected to :" & vbCrLf & vbCrLf & _
"Account Name : Commercial Suspense (SUS1)" & _
"Account Number : " & ExCap("AccNumber"), vbInformation, "Connected"
Else
strResponse = MsgBox(" The database was unable to connect to Commercial Suspense (SUS1)" & vbCrLf & vbCrLf & _
"Please check mainframe is running and that you are logged into the Commercial System. The active screen " & _
"should be one where you can type in a screen name." & vbCrLf & vbCrLf & _
"Press Ok to try again or Cancel to close the application.", vbCritical, "Unable to Connect!")
If strResponse = 1 Then
Loop
Else
MsgBox "If you have been unable to connect to EXTRA! or Commercial Suspense, " & _
"Please contact Craig Lomas (Xt: 99999 or email: me.name@mycompany.com) to get your system checked." & vbCrLf & vbCrLf & _
"The database will now close.", vbInformation, "Commercial Suspense Reader"
Application.Quit
Exit Do
End If
End If
Else
Application.Quit
End If
End Sub
====================== CODE END ========================
Apologies for the long code...
Other posts I have read seem to attribute this error to a missing "END IF" but I think I have covered them all.
If you can't loop from within an if statement how would you get around this ?
Any help appreciated
Thanks
Craig
--------------------------------------------------------------------------------------------------------
"Time-traveling is just too dangerous. Better that I devote myself to study the other great mystery of the universe: Women!" .. Dr E. Brown (1985)
Can you Loop back to a DO from within an IF statement?
I'm getting the "Loop without Do" compile error at in the following code at the red highlighted point...
Code Follows :
================= CODE START ===========================
Option Compare Database
Option Explicit
Sub RunApp()
Dim strRunResponse As String
Dim strResponse As String
Dim strSQL As String
strRunResponse = MsgBox("Do you want to run Suspense Reader?", vbQuestion + vbYesNo, "Run Application?")
If strRunResponse = 6 Then 'YES to RUN
strResponse = MsgBox("Do you want to save a copy of the last suspense reading?" & vbCrLf & vbCrLf & _
"THIS WILL OVERWRITE ALL PREVIOUSLY SAVED READINGS", vbQuestion + vbYesNo, "Save?")
If strResponse = 6 Then 'YES to SAVE
DoCmd.SetWarnings False 'Run queries to save last reading
DoCmd.OpenQuery "qrySaveLastReading"
DoCmd.OpenQuery "qrySuspenseData_DELETE"
DoCmd.SetWarnings True
Else
DoCmd.SetWarnings False 'Run queries to delete data currently in table
DoCmd.OpenQuery "qrySuspenseData_DELETE"
DoCmd.SetWarnings True
End If
MsgBox "The system will now try to connect to the Commercial Sysytem" & vbCrLf & vbCrLf & _
"Please ensure that EXTRA! Mainframe is open and that you are logged in to the Commercial System ", _
vbOKOnly, "Connecting to EXTRA!..."
'========== CONNECT LOOP ===============
Do 'Connect Loop
Extra_Connect 'Run Extra_Connect procedure
If System = "EXTRA! Personal Client" And Sess0 = "Ventura" Then 'Connected
MsgBox "Connected to :" & vbCrLf & vbCrLf & _
"System: " & System & vbCrLf & _
"Session: " & Sess0 & vbCrLf & vbCrLf & _
"Press Ok to continue...", vbOKOnly, "Connected"
Exit Do 'Exit loop if connected
Else 'Not Connected
strResponse = MsgBox("The database was unable to connect to EXTRA! Mainframe" & vbCrLf & vbCrLf & _
"Please check that EXTRA! is running and that you are logged on to the Commercial System " & _
"using your CTRF code." & vbCrLf & vbCrLf & _
"Press Ok to try again or Cancel to stop trying", vbCritical + vbOKCancel, "Unable to Connect!")
If strResponse = 1 Then
Loop 'Keep trying to connect until user clicks Cancel
Else
MsgBox "If you have been unable to connect to EXTRA!, " & _
"Please contact Craig Lomas (Xt: 99999 or email: me.name@mycompany.com) to get your system checked." & vbCrLf & vbCrLf & _
"The database will now close.", vbInformation, "Commercial Suspense Reader"
Application.Quit
Exit Do
End If
End If
'=========== END OF CONNECT LOOP ==================
MsgBox "The database will now try to connect to Commercial Suspense (SUS1)" & _
"Please ensure that the screen is clean (No Half Edited Accounts)", vbOKOnly, "Connecting to SUS1..."
Do 'Loop to connect to suspense
Goto_SUS1
If ExCap("SUSName") = "TRF Payment Suspense" Then
MsgBox "Connected to :" & vbCrLf & vbCrLf & _
"Account Name : Commercial Suspense (SUS1)" & _
"Account Number : " & ExCap("AccNumber"), vbInformation, "Connected"
Else
strResponse = MsgBox(" The database was unable to connect to Commercial Suspense (SUS1)" & vbCrLf & vbCrLf & _
"Please check mainframe is running and that you are logged into the Commercial System. The active screen " & _
"should be one where you can type in a screen name." & vbCrLf & vbCrLf & _
"Press Ok to try again or Cancel to close the application.", vbCritical, "Unable to Connect!")
If strResponse = 1 Then
Loop
Else
MsgBox "If you have been unable to connect to EXTRA! or Commercial Suspense, " & _
"Please contact Craig Lomas (Xt: 99999 or email: me.name@mycompany.com) to get your system checked." & vbCrLf & vbCrLf & _
"The database will now close.", vbInformation, "Commercial Suspense Reader"
Application.Quit
Exit Do
End If
End If
Else
Application.Quit
End If
End Sub
====================== CODE END ========================
Apologies for the long code...
Other posts I have read seem to attribute this error to a missing "END IF" but I think I have covered them all.
If you can't loop from within an if statement how would you get around this ?
Any help appreciated
Thanks
Craig
--------------------------------------------------------------------------------------------------------
"Time-traveling is just too dangerous. Better that I devote myself to study the other great mystery of the universe: Women!" .. Dr E. Brown (1985)