Auto update a combo box based on value entered in a text box

Indigo

Registered User.
Local time
Today, 19:58
Joined
Nov 12, 2008
Messages
241
I have been trying to research this option and it have had no luck in finding a solution. I am running Access 2003 and have a form with
a text box for entering a "ClosedDate" and a combo box for entering
a Status (Open or Closed).

I want the default value of the StatusID combo box to be "Open",
however, if a date has been entered into the "ClosedDate" text
box, I want the combo box value to change to "Closed". I tried
the following, without success:

Private Sub ClosedDate_AfterUpdate()
If Len([ClosedDate] & "") <> 0 Then
Me.StatusID.Requery
Me.StatusID = 2
Else
Me.StatusID = 1
End If
End Sub

You may think that having both a status indicator as well as
a closed date field is muda, but I have reasons for this based
on requests from the 100 or so users on the form. Any help
you can offer would be appreciated. Thank you.
 
This will change the combobox when a date is either entered in ClosedDate or deleted from it.

Code:
Private Sub ClosedDate_AfterUpdate()
If Len([ClosedDate] & "") <> 0 Then
  Me.StatusID = "Closed"
Else
  Me.StatusID "Open"
End If
End Sub

The question is, is ClosedDate bound to a field in your underlying table? If it is, this is all you need to do.

If, on the other hand, ClosedDate is not bound to a field in your table, you'll need to add this same code in the Form_Current event.
 
A guess... Based on what you wrote, you may also want to disable the combo...

Code:
Me.StatusID.Enabled = False

Regards,
Tim
 
Thank you for your input. The form is bound to a table and

Private Sub ClosedDate_AfterUpdate()
If Len([ClosedDate] & "") <> 0 Then
Me.StatusID = 2
Else
Me.StatusID = 1
End If
End Sub

works and it doesn't. I hope I can explain this properly. If the user, after entering the closed date by a calendar form pop-up, the StatusID combo box does not change. If they enter the date manually then the combo box changes. The calendar pop-up was added to make the form more user friendly to the user. I do not wish to remove it, but how would I get the combo box to change in that instance?

Tim, not sure what you mean by disabling my combo-box?
 
Okay, I put the same code in the

Private Sub ClosedDate_GotFocus()

and it works.....
 

Users who are viewing this thread

Back
Top Bottom