Solved

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

Posted on 2011-02-25
12
595 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34984406
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
ID: 34984453
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34984497
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 16

Expert Comment

by:Sheils
ID: 34984539
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
ID: 34984680
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34984728
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
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34984773
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
ID: 34984777
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
ID: 34984794
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
ID: 34984823
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 34984824
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
ID: 34984874
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

776 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