473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to repopulate data in form once combobox item picked?

Hi. I am very new to SQL. I am working on an Access 2007 database. I want to create a form with a combo box, which I know how to do. However, once I select the appropriate SampleID from the combo box, I would like the subform to repopulate with the correct data corresponding to the selected SampleID. This is where I am having problems. Thanks in advance for any help.

FYI, the main table is called all_net_data. Eventually, I would like to have three subforms repopulate with all the data corresponding to the specific SampleID selected (each subform corresponding to a different table).

Does this make sense? Again, I am new to Access and SQL.

Thanks,

Charlie
Jan 24 '11 #1
5 2116
Oralloy
988 Expert 512MB
Charlie,

I think you want to hang your VBA code on the combobox "Change" event, like this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboBox1_Change()
  2.   If Me.ComboBox1.value = "Field" Then
  3.     Me.Text2.value = "Test"
  4.   ElseIf Me.ComboBox1.value = "Rip" Then
  5.     Me.Text2.value = "Torn"
  6.   Else
  7.     Err.Raise 1 + VBA.Constants.vbObjectError, _
  8.               "Test Combo Box", _
  9.               "Whoops, unexpected value in Combo Box"
  10.   End If
  11. End Sub
Hopefully this helps a little.

Cheers!
Oralloy
Jan 24 '11 #2
Thanks for the reply Oralloy. Being a newbie, I am confused. First I guess I should state that I'd like the subform on the form with the combo box. In the above code, I don't really understand the Text2 part. Would that refer to text box in the subform? Also, I added this code and I received the following message: "Data member not found and it highlights the text2 in the code". So I assume I need to change the text2 in the code to the appropriate text box name. Is this correct? Also, on the subform I have about 20 text boxes refering to fields in a table, do I need to code all these separately? Thanks again,

Charlie
Jan 24 '11 #3
Oralloy
988 Expert 512MB
Charlie,

In my example, Text2 is just a text box on my form. To make it a text box on the subform, use something like:

Me.mySubform.Text2.value = "Test"

Where mySubform is declared as the type of the subform you are using, or simply as an Object.

My preference is for strong typing, but then I come from a C++ background where typing is used to prevent the user from injecting errors into the code by guarding computations and assignments at compile time. VBA does this, but you have to be patient and use the facility; the default is Variant, which accepts anything. (enough, we can discuss typing all day long).

[[Of course, it gets worse, if your sub-form has a grid display, but let's not go there, unless we have to.]]

Since your sub-form has about 20 fields, you're going to have to manage them somehow. Either you'll have to explicitly deal with the values, or you'll have the sub-form bound to a table (or query). In the later case, you'll have to build the filter and appropriate update mechanics. Essentially, you created the data, you have to manage it. There are 20 data fields there, and unless you tell VBA how to deal with them in some way or other, they'll just sit there and provide no use to your application.

Is that helpful, or were you asking for something different?

Good Luck and Cheers!
Oralloy!
Jan 24 '11 #4
Jerry Maiapu
259 100+
You said: I would like to have three subforms repopulate with all the data corresponding to the specific SampleID selected (each subform corresponding to a different table).

This would mean that the 3 subforms recordsource/table are having a one to many relationships. If so then try this on the afterupdate event of the combobox:

Expand|Select|Wrap|Line Numbers
  1.  ' Find the record that matches the control.
  2.     Dim rs As Object
  3.  
  4.     Set rs = Me.Recordset.Clone
  5.     rs.FindFirst "[ID] = " & str(Nz(Me![cmbCombo], 0))
  6.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  7.  
  8.  
Replace ID with your combo's ID and cmbCombo with you combo's name.
Jan 25 '11 #5
NeoPa
32,556 Expert Mod 16PB
Check out Example Filtering on a Form.
Jan 25 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tim Graichen | last post by:
Hi all, I think this is pretty basic, I have a simple subform that has Txtbox1 which displays the field Name from TblOne. In the same subform, I also have a ComboBox1 which displays field...
2
by: kufre | last post by:
I'm using Access 97, I have a problem with my form. I have a subform inside my form. I would like to diable the subform if submission number is 1 and enable it if it is greater than 1. I will...
1
by: Matt | last post by:
Here is my problem. I am trying to get a combo box working that lists all the models of servers that we have. This combo box is just one of many text boxes that I have on my form. I am running a...
12
by: StevoGman | last post by:
To Whomever Can Help Me, I am a very inexperienced programmer, and I am trying to create a combo box that is dependant on another combo boxes answer. For example: I have a combo box (Study...
2
by: hawg1 | last post by:
I'm fairly new to Access and need help with form/subform. I've seen another access database in which a main form allowed the user to enter school class specific information shuch as start date,...
3
by: panwala_bhavesh | last post by:
I have a form (View All Assets) with two combo boxes (ComboManufacturer & ComboProductType) and a subform with a dataview that displays the results of my query below: SELECT Assets., Assets....
2
by: docsix | last post by:
I am having trouble populating a combo box in a subform. Currently I have two combo boxes on a single form that works. This is my current setup: Table:Facilities - FacilityID ... FacilityType 1...
3
by: jonceramic | last post by:
Hi, I have a 2 subform form, which uses the selection of a row in subform 1 to show a set of rows in subform 2. I have my queries pointing directly to fields on my form to choose what data is...
3
by: luciegiles | last post by:
I'd like to start off with an apology - I posted a question on a similar matter sometime ago and didn't respond to those who took the time to answer my question. At the time i gave up but have used...
1
by: chester64 | last post by:
Hello, I have created a form with 2 comboboxes (Employee_ID & Order_Num) and 1 Subform (sfOrder_Detail). The way I'm trying to make it work is like this ... you select the Employee in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.