ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Code in use is shown below
I would like to apply a delay of say 5 seconds before the code runs.
I tried Sleep 5 at the begining but did not work for me
I would like to apply a delay of say 5 seconds before the code runs.
I tried Sleep 5 at the begining but did not work for me
VBA Code:
Private Sub ComboBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim response As Integer
Dim oNewRow As ListRow
' if combo empty stop here
If Len(Me.ComboBox1.Value) = 0 Then Exit Sub
' is entry in drop down
If Not Me.ComboBox1.MatchFound Then
' ask if to add entry to list
response = MsgBox("VEHICLE ISNT IN VEHICLE LIST" & vbCrLf & vbCrLf & "DO YOU WISH TO ADD IT ?", vbYesNo + vbCritical, "ADD VEHICLE TO LIST")
If response = vbYes Then
Application.EnableEvents = False
Application.ScreenUpdating = False
' add row to table
With Sheets("INFO").ListObjects("Table2")
Set oNewRow = .ListRows.Add
' put what was entered into list
oNewRow.Range.Cells(1) = Me.ComboBox1.Value
'** SORT A=Z HERE **
.Sort.SortFields.Clear
.Sort.SortFields.Add KEY:=.ListColumns(1).Range, SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
With .Sort
.Header = xlYes
.Apply
End With
Application.Goto (.HeaderRowRange.Cells(1))
End With
' re-activate QUOTES sheet
Sheets("QUOTES").Select
' assign the new list to combo
With Me.ComboBox1
.List = Sheets("INFO").ListObjects("Table2").DataBodyRange.Value
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
Else ' response was NOT vbYes
MsgBox Me.ComboBox1.Value & vbCrLf & "THE VEHICLE SHOWN ABOVE" & vbCrLf & "WILL NOT BE ADDED TO VEHICLE LIST", vbInformation, "VEHICLE WONT BE ADDED TO LIST MESSAGE"
' clear entry
Me.ComboBox1.Value = ""
' maintain focus
Cancel = True
Exit Sub
End If
End If
End Sub