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

    Prevent Action (A2k)

    I have a DoubleClick_Event on a combo which transfers records ie

    Forms!MyForm!txtWhatever = Me.MyCombo.Column(1) etc

    I call this event from a keycode.

    If no selection is made from the combo and I use the key event, the code still fires, how can I prevent this.

    I have tried
    .ItemsSelected = 0
    .ItemData = 0
    If IsNull(Me.MyCombo.ItemData) etc

    But the code still fires.

    I tried to trap this using a MsgBox to see if an item has not been selected, ie MsgBox "Nil" after the IsNull statement but the code just halts.
    No errors are shown.

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

    Re: Prevent Action (A2k)

    If nothing is selected, the ListIndex property is -1, otherwise it is the zero-based index of the selected item. So you can try

    If Me.MyCombo.ListIndex = -1 Then Exit Sub
    Forms!MyForm!txtWhatever = Me.MyCombo.Column(1)
    ...

    or

    If Me.MyCombo.ListIndex > -1 Then
    Forms!MyForm!txtWhatever = Me.MyCombo.Column(1)
    ...
    End If

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

    Re: Prevent Action (A2k)

    Thanks, its fine now.
    I didn't use the ListIndex, I thought that meant if anything was in the list at all.

    <pre>Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyReturn
    If Me.cmbInsurerQuickFind.ListIndex = -1 Then
    MsgBox "No Item Selected" & vbCrLf & vbCrLf & _
    "Please Select An Insurer From The List", , "!!"
    Exit Sub
    Else
    Call cmbInsurerQuickFind_DblClick(1)
    End If
    Case vbKeyF10
    DoCmd.Close acForm, Me.Name, acSaveNo
    End Select
    End Sub</pre>


Posting Permissions

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