Results 1 to 1 of 1

Thread: [RESOLVED] Forced to make an entry in a combobox!

  1. #1

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Resolved [RESOLVED] Forced to make an entry in a combobox!

    I've been through this a dozen times and can't seem to work out what's wrong!

    I have a combobox (cboGVW), which represents the gross vehicle weight of a truck. The combobox is populated with standard manufacturers weights, but sometimes a custom weight needs to be entered so .matchrequired = false.

    I am trying to:

    a) Allow numeric or null entries only.
    b) Set upper and lower limits for numeric entries.

    The code below works in every instance except for allowing null entries! Once the combobox has been selected, I'm stuck there until I enter a valid number!

    VB Code:
    1. Private Sub cboGVW_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    2.  
    3. 'GVW ENTRY FORMAT VALIDATION
    4.  
    5.     If IsNumeric(cboGVW.Value) And cboGVW.Value >= 7500 And cboGVW.Value <= 32000 Then
    6.         cboGVW.Value = Format(CInt(cboGVW.Value))
    7.     ElseIf IsNumeric(cboGVW.Value) And cboGVW.Value < 7500 Then
    8.         MsgBox "Skiploaders are not suitable for vehicles with a GVW less than 7500kg!" & vbCr & _
    9.         "Please enter a valid GVW or consult Engineering.", vbExclamation + vbOKOnly, "Invalid Entry!"
    10.         cboGVW.Value = Null
    11.         Cancel = True
    12.     ElseIf IsNumeric(cboGVW.Value) And cboGVW.Value > 32000 Then
    13.         MsgBox "Skiploaders are not suitable for vehicles with a GVW greater than 32000kg!" & vbCr & _
    14.         "Please enter a valid GVW or consult Engineering.", vbExclamation + vbOKOnly, "Invalid Entry!"
    15.         cboGVW.Value = Null
    16.         Cancel = True
    17.     ElseIf Not IsNull(cboGVW.Value) Then
    18.         MsgBox "Entries must be numeric and between 7500 and 32000!" & vbCr & _
    19.         "Please enter a valid GVW or consult Engineering.", vbExclamation + vbOKOnly, "Invalid Number Format!"
    20.         cboGVW.Value = Null
    21.         Cancel = True
    22.     Else
    23.     End If
    24.        
    25. End Sub

    As usual any help to relieve my pain would be appreciated.

    EDIT: Sometimes I should take a step back before I ask! Problem has been resolved, although constructive criticism is always welcome.

    Modified Code:

    VB Code:
    1. Private Sub cboGVW_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    2.  
    3. 'GVW ENTRY FORMAT VALIDATION
    4.  
    5.     If IsNumeric(cboGVW.Value) And cboGVW.Value >= 7500 And cboGVW.Value <= 32000 Then
    6.         cboGVW.Value = Format(CInt(cboGVW.Value))
    7.     ElseIf IsNumeric(cboGVW.Value) And cboGVW.Value < 7500 Then
    8.         MsgBox "Skiploaders are not suitable for vehicles with a GVW less than 7500kg!" & vbCr & _
    9.         "Please enter a valid GVW or consult Engineering.", vbExclamation + vbOKOnly, "Invalid Entry!"
    10.         cboGVW.Value = Null
    11.         Cancel = True
    12.     ElseIf IsNumeric(cboGVW.Value) And cboGVW.Value > 32000 Then
    13.         MsgBox "Skiploaders are not suitable for vehicles with a GVW greater than 32000kg!" & vbCr & _
    14.         "Please enter a valid GVW or consult Engineering.", vbExclamation + vbOKOnly, "Invalid Entry!"
    15.         cboGVW.Value = Null
    16.         Cancel = True
    17. [I]   [B] ElseIf IsNull(cboGVW.Value) Then 'Do nothing[/B]
    18.     [B]Else
    19.         MsgBox "Entries must be numeric and between 7500 and 32000!" & vbCr & _
    20.         "Please enter a valid GVW or consult Engineering.", vbExclamation + vbOKOnly, "Invalid Number Format!"
    21.         cboGVW.Value = Null
    22.         Cancel = True[/B][/I]    
    23.     End If
    24.        
    25. End Sub

    EDIT: It's obviously later than I thought - the above doesn't work either!!!
    Last edited by New2vba; Mar 14th, 2006 at 06:54 PM. Reason: Because it's late and I made a mistake in my solution!
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width