how to if/else and then move on? resume??

CharlesWhiteman

Registered User.
Local time
Today, 17:50
Joined
Feb 26, 2007
Messages
421
I'm using the follow piece of code but I'm getting a resume error. I think the code is self explanatory but want to find the correct way to get the code to go to the next routine when it detects 0

Code:
Dim intCriticalCount As Integer
intCriticalCount = DCount("PrimaryDataID", "QryUsePercentageLeftCritical")
If intCriticalCount = 0 Then
Resume
Else
UseLimitCritical
End If
Dim intMediumCount As Integer
intCriticalCount = DCount("PrimaryDataID", "QryUsePercentageLeftMedium")
If intMediumCount = 0 Then
Resume
Else
UseLimitMedium
End If
DoCmd.CloseDatabase
 
You probably need nested Ifs or perhaps ElseIf.

Resume is only applicable to management of error conditions.

(As for the question in your signature, not knowing how to do this and using Resume in this way indicates you are still a newbie. ;))
 
Just a quick rewrite of your original - but it still isn't necessarily right because we don't know what you are wanting returned as I think you didn't post the entire code which includes the procedure header so we can see what UseLimitCritical or UseLimitMedium are and how they relate to things.

Code:
    Dim intCriticalCount As Integer
    Dim intMediumCount As Integer
    intCriticalCount = DCount("PrimaryDataID", "QryUsePercentageLeftCritical")
    If intCriticalCount <> 0 Then
        UseLimitCritical
        Exit Function  ' I assumed that if that was valid then you would not 
                           ' go on to the medium but don't know for sure from lack of info
    End If

    intMediumCount = DCount("PrimaryDataID", "QryUsePercentageLeftMedium")
    
    If intMediumCount <> 0 Then
        UseLimitMedium
    End If
    
    DoCmd.CloseDatabase
 
Hi Bob and many thanks for your reply and guidance.

Yes, there are two functions. One medium and one critical. They relate to amounts of data used (taken from an external MySQL billing system) compared to bandwidth allowance.

The two functions are based on their own query so both do need to run but I have effectively decided to trigger each from the same OnTime event on my form. I will set the Db to open on a schedule.

So the basic principal is run through the first function but dont bother if there are no records and whatever happens go to the next function but only run it if there are records to process and then whatever happens close the database.
 
Then it would be the same as I had posted but WITHOUT the Exit Function part (oh and no Docmd.CloseDatabase - it is Application.Quit:
Code:
    Dim intCriticalCount As Integer
    Dim intMediumCount As Integer
    intCriticalCount = DCount("PrimaryDataID", "QryUsePercentageLeftCritical")
    If intCriticalCount <> 0 Then
        UseLimitCritical  
    End If
    intMediumCount = DCount("PrimaryDataID", "QryUsePercentageLeftMedium")
    
    If intMediumCount <> 0 Then
        UseLimitMedium
    End If
    
    Application.Quit
 

Users who are viewing this thread

Back
Top Bottom