473,791 Members | 3,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combo box selection populates form

2 New Member
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 2111
MSeda
159 Recognized Expert New Member
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
sstasiak
2 New Member
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,579 Recognized Expert Moderator MVP
...
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
7193
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) how to use the selection "All" as criteria for a field in a query, which is used to generate data for a report.
7
11146
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 values for the second combo box (B) from a database. However, when I choose a value from the first combo box (A), the second combo box (B) populates as required, but if i change my mind about the selection from the first combo box (A) , the second...
2
1591
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 box and have the cmboStreet combo box populated with the Street from that city. The program only works one time. That is, I select a city from cmboCity and
2
1909
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 ............ Bus 2 ............ Library Table: Additional DetailID .... Details .............. FacilityID 1 ..............TImetable .......... Bus
7
1612
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: SELECT DISTINCT !field2AS Expr1 FROM WHERE (((.field1)=Forms!form1!combo0)); So basically, the user selects from the first combo box which field1 value they want to limit their returned recordset to. Then the second combo box populates with all...
6
8278
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 populated are lsited below but must be recorded to a new table. Gets info from Course occurance Table. Combo Box - Gets Information from Course Occurance Table. This table has all information regarding course information. Course ID: Course...
6
3684
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
2292
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 selection the user chooses when logging in (code below). Basically, the user selects their office at login and the textbox will populate with the appropriate return mailing address when frmEditReport opens. I think this is most efficient since...
1
2518
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 combo box, which that selection populates the next combo for the course selection. I have managed to do that with the coding shown below, my next combo will work from the course selection to bring back the feedback topics associated with that course,...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.