Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Seems like a day for combo's !! (A2k)

    With the following code, I cannot get the setfocus and backspace at the end to work correctly.
    The next combo after cmbModelSelect is cmbVehicleStyle.
    No matter where I put the code, the next combo still recieves the focus.
    Here is the On_Enter & On_Exit codes.
    It may be I've missed something.:-

    <pre>Private Sub cmbModelSelect_Enter()
    If IsNull([cmbModelSelect]) Then
    [cmbModelSelect].Dropdown
    End If
    End Sub</pre>


    <pre>Private Sub cmbModelSelect_Exit(Cancel As Integer)
    If IsNull(Me.cmbModelSelect) Then
    Dim intButSelected As Integer, intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String

    strMsgPrompt = "You Must Enter A Model Derivitive" & vbCrLf & _
    "Or Select An Existing Derivitive" & _
    vbCrLf & "From The Drop Down Box"
    strMsgTitle = "Dirivitive Selection"

    intButType = vbOKOnly + vbExclamation + vbDefaultButton1
    intButSelected = MsgBox(strMsgPrompt, intButType, strMsgTitle)

    If intButSelected = vbOKOnly Then
    ' OK button code...
    DoCmd.CancelEvent 'Not sure if this is needed !!
    Forms!frmVehicleAdmin.SetFocus
    Forms!frmVehicleAdmin!cmbModelSelect.SetFocus
    SendKeys "{backspace}"

    End If
    Exit Sub
    End If
    End Sub</pre>


    The form this combo resides on is frmVehicleAdmin, so the setfocus section
    at the end may be better with Me.CmbModelSelect.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Seems like a day for combo's !! (A2k)

    The problem here is that you should test for a return value of vbOK, not vbOKOnly. But I don't understand why you use all this code if you display a message box with only an OK button - the user has no choice.

    I would use this:<pre>Private Sub cmbModelSelect_Exit(Cancel As Integer)
    Dim intButType As Integer
    Dim strMsgPrompt As String, strMsgTitle As String
    If IsNull(Me.cmbModelSelect) Then
    strMsgPrompt = "You Must Enter A Model Derivative" & vbCrLf & _
    "Or Select An Existing Derivative" & _
    vbCrLf & "From The Drop Down Box"
    strMsgTitle = "Derivative Selection"
    intButType = vbExclamation
    MsgBox strMsgPrompt, intButType, strMsgTitle
    Cancel = True
    Me.cmbModelSelect.Dropdown
    End If
    End Sub</pre>

    Note that there is no test for the return value of the message box, since it will always be vbOK. And Cancel = True is used instead of DoCmd.CancelEvent. I added an instruction to drop down the list again.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Seems like a day for combo's !! (A2k)

    Yes I see now, again Cancel as Integer has come into force.
    Thanks for the help.

Posting Permissions

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