473,327 Members | 2,103 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,327 software developers and data experts.

Combo box selection populates form

Hello all

I have read similar threads on this site, but can't seem to get any of the solutions working for me.

I have a main form(OncRegMain) that adds records to a table(tblOncReg). This table has a primary key(MEDRECNO).

What I want to do is create a search form with a combo box containing field columns: MEDRECNO, LNAME, and FNAME from tblOncRegMain. When the appropriate record is selected from the combo box, I want to be able to hit enter and have the form OncRegMain open with all the fields in the form populated with the data associated with the combo box selection.

I know how to create the combo box with the appropriate columns, but have no idea what to do for the "On Enter" action so that for OncRegMain opens with the fields populated.

Any ideas?

Thanks in advance
Feb 22 '07 #1
3 2080
MSeda
159 Expert 100+
Firstly, the "on Enter" event occurs when the user first enters the control not when the user presses enter while in the control.
you want to use the key down event, this event occurs whenever the user presses any key while in the control.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combobox1_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3. If KeyCode = 13 Then  '13 is the enter key so the event only occurs when the enter key is pressed
  4. Docmd.openform “OncRegMain”, ,,”[MEDREDNO] =  ” & me.Combobox1   'open the form where medrecno matches the record in your combobox assuming medrecno is the bound column of the combobox otherwise refer to its column
  5. Docmd.close acform, me.form.name  'close the search form
  6. End If
  7.  
  8. End Sub
Feb 22 '07 #2
MSeda

Thanks for the reply. I'm still having problems though. Here's exactly what I'm doing....maybe you can see where I'm going wrong.

In a blank form I added a combo box that includes fields: MEDRECNO, LNAME, and FNAME. Sort ascending by LNAME. Combo box label is MEDRECNO. Listed as 'Combo8' in the property sheet.

I click on the combo boxs' dropdown(which says 'unbound'), and go to code builder for the 'On Key Down' event. Then I paste this in:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combobox1_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3. If KeyCode = 13 Then  '13 is the enter key so the event only occurs when the enter key is pressed
  4. Docmd.openform “OncRegMain”, ,,”[MEDREDNO] =  ” & me.Combobox1   'open the form where medrecno matches the record in your combobox assuming medrecno is the bound column of the combobox otherwise refer to its column
  5. Docmd.close acform, me.form.name  'close the search form
  6. End If
  7.  
  8. End Sub
Some changes that I think should be made for my specific problem is:

Change:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combobox1_KeyDown(KeyCode As Integer, Shift As Integer)
To:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo8_KeyDown(KeyCode As Integer, Shift As Integer)
Then change:
Expand|Select|Wrap|Line Numbers
  1. Docmd.openform “OncRegMain”, ,,”[MEDREDNO] =  ” & me.Combobox1
To:
Expand|Select|Wrap|Line Numbers
  1. Docmd.openform “OncRegMain”, ,,”[MEDREDNO] =  ” & me.Combo8
For the above line, MEDRECNO is the first column in the combo box, and the bound column is set to 1. Does that mean that MEDRECNO is the bound column?

When I do this and test it, I get a syntax error on the following line:
Expand|Select|Wrap|Line Numbers
  1. Docmd.openform “OncRegMain”, ,,”[MEDREDNO] =  ” & me.Combobox1   'open the form where medrecno matches the record in your combobox assuming medrecno is the bound column of the combobox otherwise refer to its column
When I first paste the whole series of code, the above line shows up in red(don't know what that means). It also highlights [MEDRECNO] on that line and says Compile Error: "Expected end of statement". Is the syntax correct or should there be quotes removed or added somewhere?
Feb 22 '07 #3
NeoPa
32,556 Expert Mod 16PB
...
When I do this and test it, I get a syntax error on the following line:
Expand|Select|Wrap|Line Numbers
  1. Docmd.openform “OncRegMain”, ,,”[MEDREDNO] =  ” & me.Combobox1   'open the form where medrecno matches the record in your combobox assuming medrecno is the bound column of the combobox otherwise refer to its column
You still refer on this line to MEDREDNO (Not MEDRECNO) and Combobox1 (Not Combobox8).
Also, if you look carefully, you'll see the string quotes (") are not really (") at all but similar characters which won't work as quotes in VBA.
Feb 26 '07 #4

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

Similar topics

4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
7
by: Doug | last post by:
Hi I have a combo box (A) that populates a following combo box (B) based on a selection. The selection from the first combo box (A) initiates an OleDbDataAdapter routine that extracts the...
2
by: RICHARD BROMBERG | last post by:
I have a table which contains a City field and a Street field and some other fields. The main form has two combo boxes cmboCity and cmboStreet I want to select a city from then cmboCity combo...
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...
7
by: raneking22 | last post by:
I have a form with 2 combo boxes in it. The first combo box is named combo0 and has as its row source: SELECT DISTINCT !field1 FROM ORDER BY ; The second combo box has as its row source: ...
6
by: zuchowra | last post by:
Hi everyone. I need help. I have a combo box in my form that i want to populate multiple text boxes after you select your selection in the combo box. Here is my set up. The Fields that need to be...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: martin DH | last post by:
Hello, I have a unique situation, I believe. I have a form with unbound textboxes (frmEditReport) - most populate from a search query but one unbound textbox, txt_ReturnInfo, populates based on a...
1
by: didihynes | last post by:
Hi Guys, I'm in desparate need of help. I am producing a database for my dissertation and have got majorly stuck. I am currently creating a form in which the user will select a student from a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.