Form Textbox not showing correct value

Seandobson2402

New Member
Joined
Feb 9, 2018
Messages
23
Hi All,

I have the below routinefor my userform to show a Points System (1.1, 1.2, 2.1, 2.2, 3 & 4)

I seem to be having trouble with the line - If CatPoints < 85 Then SohoCat = 2.2 Else SohoCat = 3.. My form brings up 2 as the Value instead of 2.2. I have no idea why.

Code:
Private Sub PointsCat()
    Dim SohoCat As Long
    Dim VergeCoeff As Long, FootwayCoeff As Long
    Dim CatPoints As Long
    Dim AllCivilsEntered As Boolean
    'linear equation coefficients for cat calculation
    VergeCoeff = 1
    FootwayCoeff = 5
    
    With Me
    
        'set the colours to red if not value not entered, off white otherwise
        If .cbVergeM.Value = "" Then .cbVergeM.BackColor = &HFF& Else .cbVergeM.BackColor = &H80000005
        If .cbFootwayM.Value = "" Then .cbFootwayM.BackColor = &HFF& Else .cbFootwayM.BackColor = &H80000005
        If .cbCarriagewayM.Value = "" Then .cbCarriagewayM.BackColor = &HFF& Else .cbCarriagewayM.BackColor = &H80000005
        If .cbSpecialistPavingM.Value = "" Then .cbSpecialistPavingM.BackColor = &HFF& Else .cbSpecialistPavingM.BackColor = &H80000005
        
        'determine if all civils have been entered
        AllCivilsEntered = .cbVergeM.Value <> "" And .cbFootwayM.Value <> "" And .cbCarriagewayM.Value <> "" And .cbSpecialistPavingM.Value <> ""
        
        If AllCivilsEntered Then
            'initialise
            CatPoints = 0
            'first condition
            If .cbSpecialistPavingM.Value = 1 Or .cbSpecialistPavingM.Value = 2 Then CatPoints = 20
            'continue with second condition (equation)
            CatPoints = CatPoints + VergeCoeff * .cbVergeM.Value + FootwayCoeff * .cbFootwayM.Value
            'this takes precedence
            If CatPoints < 85 Then SohoCat = 2.2 Else SohoCat = 3
            If .cbCarriagewayM.Value <> 0 Or .cbSpecialistPavingM.Value > 2 Then SohoCat = 3
            'update the points label... this is made visible/invisible by the tests in the calling routine
            .lPoints.Caption = "Points= " & CatPoints
            .tSoCatResult.BackColor = &H80000005
            .tSoCatResult.Value = SohoCat
        Else
            'set the colours to red if value not entered, off white otherwise
            If .cbVergeM.Value = "" Then .cbVergeM.BackColor = &HFF& Else .cbVergeM.BackColor = &H80000005
            If .cbFootwayM.Value = "" Then .cbFootwayM.BackColor = &HFF& Else .cbFootwayM.BackColor = &H80000005
            If .cbCarriagewayM.Value = "" Then .cbCarriagewayM.BackColor = &HFF& Else .cbCarriagewayM.BackColor = &H80000005
            If .cbSpecialistPavingM.Value = "" Then .cbSpecialistPavingM.BackColor = &HFF& Else .cbSpecialistPavingM.BackColor = &H80000005
            .tSoCatResult.BackColor = &HFF&
            .tSoCatResult.Value = "N/A"
        End If
        
    End With
    
End Sub
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Watch MrExcel Video

Forum statistics

Threads
1,109,073
Messages
5,526,655
Members
409,713
Latest member
roman9980

This Week's Hot Topics

Top