Link to home
Start Free TrialLog in
Avatar of daintysally
daintysallyFlag for United States of America

asked on

How to set the value of combo boxes and textboxes equal to null

Hi Experts,

I have a form that is bound to a table in access 2007.  How do I set the values of the form to null until the user makes a selection from the drop-down combo box?  When the user opens the form, the combo box is null, but the other boxes are populated with other information from the first record.  Right now, the user selects from the first combo box on the form and the rest of the form populates with information from that record.  Can someone help me solve this quickly?

 
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

if you are adding new record, set the DataEntry property of the form to Yes
or open the form in code in Data entry mode
Avatar of daintysally

ASKER

I am not adding a new record. I am pulling the record so that the user can make changes to whatever record they select
ok,
use an Unbound Combo box.
in the afterupdate event of the combo, find the corresponding record

private sub combo1_afterupdate()

with me.recordsetclone
      .findfirst "[Id]=" & me.combo1
      if not .nomatch then
          me.bookmark =.bookmark
      else
         msgbox "record not found"
     end if
end with

end sub



post the rowsource of the combo box...




I believe that what you are trying to do is to use the combo box to search for a record or to use a better term filter through record.

If this is the case then you have to use an unbounded combo box.

Then you can change the recordsource of the form base on what has been selected in the combo box. let me know if that what you want to do and I will send you an example
Yes, this is exactly what I want to do. I already have the unbound combo box.  I want the user to select an ID from the combo box and when it has been selected, the rest of the form is populated with the information from that record.
see the codes i posted above, just change the name of the field [Id] to actual field name and comob1 with actual name of combo box
Here is my code for such an unbound combo box:
Private Sub cboSelect_AfterUpdate()
'Written by Helen Feddema 29-Jun-2009
'Last modified 11-Feb-2010

On Error GoTo ErrorHandler

   Dim strSearch As String

   'For text IDs
   strSearch = "[______ID] = " & Chr$(39) & Me.ActiveControl.Value _
      & Chr$(39)

   'For numeric IDs
   strSearch = "[______ID] = " & Me.ActiveControl.Value

   'Find the record that matches the control
   Me.Recordset.FindFirst strSearch

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in " & Me.ActiveControl.Name & " procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

This will not set the values of the controls on the form to Null, however; it will display the values for the selected record.
Yes, I want to display the values for the selected record.  I just want the user to see a blank textboxes and combo boxes when they first open the form.  Then when they make a selection from the dropdown combo box, everything will display.  Then when the form is closed, all of the values in all of the textboxes and combo boxes are reset to null until another user selects a different 'ID'
Use the following code for the onchange even of the unbounded combo box

Private Sub ComboxName_Change()

Me.BoundControlName.SetFocus
DoCmd.FindRecord Me.ComboxName

End Sub

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you everyone for your help!!!  capricorn1 your solution worked perfectly.  I had a macro in the afterupdate event of the combo box and all that I had to do was add 'requery'.  Thank you!!!