Combo box invalid use of null

DYH

New member
Local time
Today, 11:44
Joined
Apr 1, 2014
Messages
5
We just upgraded to Office 2010 from 2003 and I am now getting 'invalid use of null' after choosing a valid combo box option. When I debug, the line that highlights has to do with a text box on the form rather than the combo box. Here's the code highlighting:

frmLines = Me.WorkLoadUnit

This is the code in it's entirety.

Private Sub fsubProductivityInput_Calculations()
On Error GoTo err
'Calculate Breaks and Net Hours
Dim frmLines As Double
Dim frmHours As Double
Dim frmLPH As Double

frmLines = Me.WorkLoadUnit
frmHours = Me.Hours

'Calculate Lines Per Hour
frmLPH = (frmLines / frmHours)
'Set Feild
Me.AveragePerformanceResults = frmLPH

'Calculate % to Average
Dim frmHighPerformanceResults As Double
Dim frmAnticipatedPerformanceResults As Double
Dim frmLowPerformanceResults As Double
Dim frmSpread As Variant
Dim frmAveragePercent As Double

'Pulls the numbers out of the combo box and place them in the subform'''''''''''''''''''''''''''
frmHighPerformanceResults = [HighPerformanceResults]
frmAnticipatedPerformanceResults = [AnticipatedPerformanceResults]
frmLowPerformanceResults = [LowPerformanceResults]

'Calculate Spread and % to Average
frmSpread = frmHighPerformanceResults - frmAnticipatedPerformanceResults
frmAveragePercent = ((frmLPH - frmAnticipatedPerformanceResults) / frmSpread)
'Set Feild
Me.AveragePercent = frmAveragePercent
Exit_Err:

Exit Sub

err:
'DoCmd.beep
'MsgBox err.Description
'MsgBox "Please enter the number of Lines performed on this task", , "Possible Mistake"
'Me.WorkLoadUnit.SetFocus

Resume Exit_Err
End Sub

Any thoughts/suggestions?
 
Use CODE tags, then highlight the line of code that is causing the error.
 
Apologies! New to VBA and coding forums. See red text.

Code:
Private Sub fsubProductivityInput_Calculations()
On Error GoTo err
'Calculate Breaks and Net Hours
    Dim frmLines As Double
    Dim frmHours As Double
    Dim frmLPH As Double
    
    [COLOR=red]frmLines = Me.WorkLoadUnit[/COLOR]
    frmHours = Me.Hours
    
   'Calculate Lines Per Hour
    frmLPH = (frmLines / frmHours)
       'Set Feild
        Me.AveragePerformanceResults = frmLPH
    
   'Calculate % to Average
    Dim frmHighPerformanceResults As Double
    Dim frmAnticipatedPerformanceResults As Double
    Dim frmLowPerformanceResults As Double
    Dim frmSpread As Variant
    Dim frmAveragePercent As Double
   
   'Pulls the numbers out of the combo box and place them in the subform'''''''''''''''''''''''''''
    frmHighPerformanceResults = [HighPerformanceResults]
    frmAnticipatedPerformanceResults = [AnticipatedPerformanceResults]
    frmLowPerformanceResults = [LowPerformanceResults]
   
   'Calculate Spread and % to Average
    frmSpread = frmHighPerformanceResults - frmAnticipatedPerformanceResults
    frmAveragePercent = ((frmLPH - frmAnticipatedPerformanceResults) / frmSpread)
       'Set Feild
        Me.AveragePercent = frmAveragePercent
Exit_Err:
    
    Exit Sub
    
err:
    'DoCmd.beep
    'MsgBox err.Description
    'MsgBox "Please enter the number of Lines performed on this task", , "Possible Mistake"
    'Me.WorkLoadUnit.SetFocus
    
    Resume Exit_Err
End Sub
 
Have you left the Me.WorkLoadUnits blank when this Routine is called? If so, try wrapping them in Nz function.
Code:
frmLines = Nz(Me.WorkLoadUnit, 0)
Do the same for all other variables.
 
After the combo box which gives the error the next tab stop is for WorkLoadUnits. This just started after upgrading to 2010. So there may be other code that is calling this sub too soon?
The reason I ask is that after entering the suggested code, the offensive line became the very next line: frmHours = Me.Hours so I used Nz for that one too. Now the offensive line is the calculation:

Code:
frmLines = Nz(Me.WorkLoadUnit, 0)
    frmHours = Nz(Me.Hours, 0)
    
   'Calculate Lines Per Hour
    [COLOR=red]frmLPH = (frmLines / frmHours)[/COLOR]
       'Set Feild
        Me.AveragePerformanceResults = frmLPH

Thanks for your help! These are 'inherited' dbs.
 
That is a Divide by Zero error. You need to be careful, it is best if you validate every entry.
Code:
Private Sub fsubProductivityInput_Calculations()
On Error GoTo errHandle
[COLOR=Green]'Calculate Breaks and Net Hours[/COLOR]
    
    If Len(Me.WorkLoadUnit & vbNullString) = 0 Or Len(frmHours & vbNullString) = 0 Then
        Msgbox "Please make sure you have entered all required information.", vbCritical, "Error processing"
        Exit Sub
    End If
        
   [COLOR=Green]'Calculate Lines Per Hour[/COLOR]
    frmLPH = (Me.WorkLoadUnit / Me.Hours)
    
   [COLOR=Green] 'Set Feild[/COLOR]
    Me.AveragePerformanceResults = frmLPH
    
  [COLOR=Green] 'Calculate % to Average
   'Calculate Spread and % to Average[/COLOR]
    'Set Feild
    Me.AveragePercent = ((frmLPH - [AnticipatedPerformanceResults]) / ([HighPerformanceResults] - [AnticipatedPerformanceResults]))
Exit_Err:
    Exit Sub
errHandle:
    DoCmd.beep
    MsgBox Err.Description
    MsgBox "Please enter the number of Lines performed on this task", , "Possible Mistake"
    Me.WorkLoadUnit.SetFocus
    
    Resume Exit_Err
End Sub
 
Null error is gone but I'm getting something else now. I will work through the latest and see what I can conclude...might be back! Thanks for your assistance!
 

Users who are viewing this thread

Back
Top Bottom