View Full Version : Combo box to show to default to null


Dgavilanes
03-13-2002, 10:35 AM
I have a 'Name List' Combo box that updates a form after each selection and works fine.
The problem is, it remains in the last name selected, I would like to see the combo box to default to a null.
Any help will be greatly appreciated.
Dennis

chuckgoss
03-13-2002, 10:50 AM
I have resolved this many times throughout the forms in my switchboard. It's cheating but I make an unbound textbox (called ctlCoverup or something)- tab stop NO, place it over the text portion of the combobox, and at the appropriate time make it visible = True, or visible = False. When placed over the combo in an invisable state, it's as if it's not there...i.e. the focus goes right through.

ctlCoverup.Visible = True
ctlCoverup.Visible = False

chuck

David R
03-13-2002, 02:40 PM
I may be missing something, but why wouldn't Me.Combo = "" work?

chuckgoss
03-14-2002, 08:16 AM
When I used that method of making null the combo box in my application, it would empty the field in the table of the record that the combo box initially displayed. Sure it would show a null, but it showed it because it had made the field on the table null.

chuck

David R
03-14-2002, 01:36 PM
Perhaps I misunderstood. You have a (bound) combo box on your table that you would like to display as being empty, even though it's not?

My answer was tailored toward an unbound combo, like a search box. Sorry if I misunderstood.

David R

David R
03-15-2002, 11:12 AM
From your email:
You are correct, it is an unbound combo box that searches from the tbl_employee and populates the basic heading information.
There are about 50 names in this *table.

After selecting* a particular name like John Doe** that name remains on top of the list. would like to see it blank, null,etc

An unbound combo box should have no way of emptying the underlying table's field unless you're doing something in code.
What is the Row Source Property (under the Data tab) for your unbound combo box? What code are you using associated with this combo box to make it do what you want, so far?

Here's what I use for an unbound combo box that blanks itself after I find the record in question:ParticipantID_Lookup:
Row Source: SELECT [tableParticipants].[ParticipantID] FROM tableParticipants;

Private Sub ParticipantID_Lookup_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Dim PIL As String

If (IsNull(Me.ParticipantID_Lookup)) Or (Me.ParticipantID_Lookup = "") Then Exit Sub

'Include check for Len(ParticipantID) = 6
PIL = Left(Me.ParticipantID_Lookup, 6)
If (Len(PIL) < 6) Then
MsgBox ("Make sure the ParticipantID has 6 characters.")
Exit Sub
End If

Set rs = Me.Recordset.Clone

rs.FindFirst "[ParticipantID] = '" & PIL & "'"

If rs.Nomatch = True Then
If (Me.NewRecord = True) Then
If (Me.Dirty = True) Then Me.Undo
Else
DoCmd.GoToRecord , , acNewRec
End If

Me.ParticipantID = Left(PIL, 6)
Me.ParticipantID_Lookup = ""
Else
'Go to the matching record
Me.Bookmark = rs.Bookmark

End If

Me.ParticipantID_Lookup.Requery
Me.subformDevices.Requery
Set rs = Nothing
End Sub

And then in the Form's Current event (you won't need all of this, but I wanted you to see what I used):
Private Sub Form_Current()
'Interfaces with ParticipantID_Lookup_AfterUpdate() to clear the lookup box and where to set the cursor
If (Me.ParticipantID_Lookup = "") Then 'No lookup, just browsing records
Me.ParticipantID_Lookup.SetFocus
Exit Sub
Else

If Me.NewRecord = False Then
'Old record, don 't want to change the ParticipantID unwittingly
Me.ParticipantID.Locked = True
Me.FirstName.SetFocus

Else
'New record
Me.ParticipantID.Locked = False
Me.ParticipantID.SetFocus
End If

Me.ParticipantID_Lookup = ""

End If

End Sub


Might be a bit overkill, but see if that helps.

David R