Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    May 2003
    Location
    Manchester, Gtr Manchester, England
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts

    force fields (2000)

    Hello, have a combo where if a certain value is selected I then need to have a second field (a date field) forced so that the user has to enter a date. How can I code this in VBA? So if combo is called received and if value 1 is selected I then need to have field 'date' forced before user can move on.

    Thanks

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

    Re: force fields (2000)

    You can set focus to the date text box in the After Update event of the combo box.
    You can check whether a date has been entered in the Before Update event of the date text box. (I wouldn't actually call it 'date' since that is a built-in function)

    With a combo box named cmbReceived and a text box named txtDate:

    Private Sub cmbReceived_AfterUpdate
    ' Did the user select 1?
    If Me.cmbReceived = 1 Then
    ' If so, set focus to the date text box.
    Me.txtDate.SetFocus
    End If
    End Sub

    Private Sub txtDate_BeforeUpdate(Cancel As Integer)
    ' Did the user select 1 in the combo box and leave the date blank?
    If Me.cmbReceived = 1 And IsNull(Me.txtDate) Then
    ' If so, issue a warning ...
    MsgBox "You MUST enter a date!", vbInformation
    ' ... and cancel the update.
    Cancel = True
    End If
    End Sub

Posting Permissions

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