Solved

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

Posted on 2011-02-25
12
575 Views
Last Modified: 2012-05-11
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?

 
0
Comment
Question by:daintysally
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
0
 

Author Comment

by:daintysally
Comment Utility
I am not adding a new record. I am pulling the record so that the user can make changes to whatever record they select
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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...




0
 
LVL 16

Expert Comment

by:Sheils
Comment Utility
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
0
 

Author Comment

by:daintysally
Comment Utility
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.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
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

0
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
This will not set the values of the controls on the form to Null, however; it will display the values for the selected record.
0
 

Author Comment

by:daintysally
Comment Utility
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'
0
 
LVL 16

Expert Comment

by:Sheils
Comment Utility
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

0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
set the record source of the form to

select * from tableName
where [id]=Forms!nameofForm!Combo1


now all you have to do now is to requery the form in the after update of the combo box

private sub combo1_afterupdate()

me.requery

end sub
0
 

Author Closing Comment

by:daintysally
Comment Utility
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!!!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now