473,671 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combo Box -- How do I...

Okay, here's the deal:

Let's say a form is based on a table.

This form has Field1 (PrimeKey), Field2, Field3, etc.

This form also has a subform which shows related records in another
table. The main fields on the main form (Field1, Field2, etc.) are
simply there for show, not for editing.

Now, I would like to set Field1 as a Combo Box so that the user
can simply select the value of this field from its list. I want to
offer this because I think there's a chance my end users will not
always want to do a filter.

Upon selecting from the Combo Box, all the other displayed fields on
the form should change to reflect the current record being displayed.

But it seems that no matter what I try -- which so far mainly has been
binding the Combo Box to the field in question and loading the rows
with the values in that field -- Access thinks that I'm trying to
*change* the contents of that field. This is not what I want. I
simply want the user to select one of the items as a means of
displaying that particular record.

And when I set the Locked property of the Combo Box to True, Access
still displays the list, but it won't let me pick one.

How do I solve this? Do I need to write code to do what I want?

Thanx in advance!
Apr 3 '06 #1
7 1838
"Erich Kohl" <ek***@sbcgloba l.net> wrote in message
news:e6******** *************** *********@4ax.c om...
Okay, here's the deal:

Let's say a form is based on a table.

This form has Field1 (PrimeKey), Field2, Field3, etc.

This form also has a subform which shows related records in another
table. The main fields on the main form (Field1, Field2, etc.) are
simply there for show, not for editing.

Now, I would like to set Field1 as a Combo Box so that the user
can simply select the value of this field from its list. I want to
offer this because I think there's a chance my end users will not
always want to do a filter.

Upon selecting from the Combo Box, all the other displayed fields on
the form should change to reflect the current record being displayed.

But it seems that no matter what I try -- which so far mainly has been
binding the Combo Box to the field in question and loading the rows
with the values in that field -- Access thinks that I'm trying to
*change* the contents of that field. This is not what I want. I
simply want the user to select one of the items as a means of
displaying that particular record.

And when I set the Locked property of the Combo Box to True, Access
still displays the list, but it won't let me pick one.

How do I solve this? Do I need to write code to do what I want?

Thanx in advance!

The key to this trick is that the combobox needs to be unbound - that is
your combobox should have a blank ControlSource. Then you write code in the
AfterUpdate event to say what should happen.
Perhaps the form will be re-set to have one record: "SELECT * FROM MyTable
WHERE ID=237"
Perhaps you will only filter on this record
Perhaps you leave all records showing - just go to the selected record.

Apr 3 '06 #2
On Mon, 3 Apr 2006 23:06:47 +0100, "Anthony England"
<ae******@oops. co.uk> wrote:

The key to this trick is that the combobox needs to be unbound - that is
your combobox should have a blank ControlSource. Then you write code in the
AfterUpdate event to say what should happen.
Perhaps the form will be re-set to have one record: "SELECT * FROM MyTable
WHERE ID=237"
Perhaps you will only filter on this record
Perhaps you leave all records showing - just go to the selected record.


I got it to work, however...

How do I get it so that _all_ the records continue to be displayed,
instead of just the one?

I put in a SELECT statement inside AfterUpdate, however it causes the
recordset to filter down to just that single record with the right ID.

Can I navigate somehow -- inside the code -- with a FindFirst type of
method?

Thanks again for your help.
Apr 4 '06 #3
"Erich Kohl" <ek***@sbcgloba l.net> wrote in message
news:9e******** *************** *********@4ax.c om...
On Mon, 3 Apr 2006 23:06:47 +0100, "Anthony England"
<ae******@oops. co.uk> wrote:

The key to this trick is that the combobox needs to be unbound - that is
your combobox should have a blank ControlSource. Then you write code in
the
AfterUpdate event to say what should happen.
Perhaps the form will be re-set to have one record: "SELECT * FROM MyTable
WHERE ID=237"
Perhaps you will only filter on this record
Perhaps you leave all records showing - just go to the selected record.


I got it to work, however...

How do I get it so that _all_ the records continue to be displayed,
instead of just the one?

I put in a SELECT statement inside AfterUpdate, however it causes the
recordset to filter down to just that single record with the right ID.

Can I navigate somehow -- inside the code -- with a FindFirst type of
method?

Thanks again for your help.

FindFirst is exactly what you should use.
For example, if you had a table "tblContact " with an autonumber primary-key
field called "ConID" you would create a combobox on the form with no
ControlSource, ConID as the first column and a BoundColumn of 1. If the
combo was named "cboConID" the code in the AfterUpdate event might be:
Private Sub cboConID_AfterU pdate()

On Error GoTo Err_Handler

Dim lngConID As Long

lngConID = CLng(Nz(Me.cboC onID.Value, 0))

If lngConID > 0 Then
With Me.RecordsetClo ne
.FindFirst "ConID=" & CStr(lngConID)
If .NoMatch Then
MsgBox "Cannot locate record" & vbCrLf & _
"ConID=" & CStr(lngConID), _
vbExclamation
Else
Me.Recordset.Bo okmark = .Bookmark
End If
End With
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Apr 4 '06 #4
On Tue, 4 Apr 2006 09:28:19 +0100, "Anthony England"
<ae******@oops. co.uk> wrote:

FindFirst is exactly what you should use.
For example, if you had a table "tblContact " with an autonumber primary-key
field called "ConID" you would create a combobox on the form with no
ControlSourc e, ConID as the first column and a BoundColumn of 1. If the
combo was named "cboConID" the code in the AfterUpdate event might be:

Private Sub cboConID_AfterU pdate()

End Sub


I coded it the way you described, and it works perfectly.

Now, uh . . . heh . . . one more question (and then I'll leave you
alone, I promise!). ;-)

What event occurs when the user clicks on the record navigation
buttons? I want the text in the combo box to change when that
happens.
Apr 4 '06 #5

"Erich Kohl" <ek***@sbcgloba l.net> wrote in message
news:de******** *************** *********@4ax.c om...
On Tue, 4 Apr 2006 09:28:19 +0100, "Anthony England"
<ae******@oops. co.uk> wrote:

FindFirst is exactly what you should use.
For example, if you had a table "tblContact " with an autonumber
primary-key
field called "ConID" you would create a combobox on the form with no
ControlSource , ConID as the first column and a BoundColumn of 1. If the
combo was named "cboConID" the code in the AfterUpdate event might be:

Private Sub cboConID_AfterU pdate()

End Sub


I coded it the way you described, and it works perfectly.

Now, uh . . . heh . . . one more question (and then I'll leave you
alone, I promise!). ;-)

What event occurs when the user clicks on the record navigation
buttons? I want the text in the combo box to change when that
happens.

Don't worry about asking - I don't mind answering.
The event you are looking for is the Current event, and you could write
something like this to make sure the combobox stays synchronized with the
current record. It basically says, when a record becomes current check to
see if the id of the combobox matches the id of the record. If not change
the value of the combobox so it matches:
Private Sub Form_Current()

On Error GoTo Err_Handler

Dim lngConID As Long

lngConID = CLng(Nz(Me!ConI D, 0))

If lngConID > 0 Then
If Nz(Me.cboConID, 0) <> lngConID Then
Me.cboConID = lngConID
End If
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Apr 4 '06 #6
Erich Kohl <ek***@sbcgloba l.net> wrote in
news:de******** *************** *********@4ax.c om:
On Tue, 4 Apr 2006 09:28:19 +0100, "Anthony England"
<ae******@oops. co.uk> wrote:

FindFirst is exactly what you should use.
For example, if you had a table "tblContact " with an
autonumber primary-key field called "ConID" you would create a
combobox on the form with no ControlSource, ConID as the first
column and a BoundColumn of 1. If the combo was named
"cboConID" the code in the AfterUpdate event might be:

Private Sub cboConID_AfterU pdate()

End Sub


I coded it the way you described, and it works perfectly.

Now, uh . . . heh . . . one more question (and then I'll leave
you alone, I promise!). ;-)

What event occurs when the user clicks on the record
navigation buttons? I want the text in the combo box to
change when that happens.

The OnCurrent event triggers whenever you change records.
--
Bob Quintal

PA is y I've altered my email address.
Apr 4 '06 #7
On Tue, 4 Apr 2006 22:26:22 +0100, "Anthony England"
<ae******@oops. co.uk> wrote:

Don't worry about asking - I don't mind answering.
The event you are looking for is the Current event, and you could write
something like this to make sure the combobox stays synchronized with the
current record. It basically says, when a record becomes current check to
see if the id of the combobox matches the id of the record. If not change
the value of the combobox so it matches:
Private Sub Form_Current()

On Error GoTo Err_Handler

Dim lngConID As Long

lngConID = CLng(Nz(Me!ConI D, 0))

If lngConID > 0 Then
If Nz(Me.cboConID, 0) <> lngConID Then
Me.cboConID = lngConID
End If
End If

Exit_Handler :
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


Thanks, guys.

I have an Office Specialist certificate for Access, but it really
didn't involve knowing anything about programming in VBA. This is why
I've been asking for help.
Apr 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4305
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
4
4274
by: Heather | last post by:
Hi I am desparately looking for advice in relation to storing the results after selecting items from two combo boxes on a Referral form. The first combo box 'ctl Type' displays a full list of Agency Types, then the 2nd combo box displays a list of Organisations, depending upon the Agency Type Selected. The first combo box 'ctlType' (Unbound), Row Source: to field in 'AgencyReferralType'.
6
3546
by: Support4John | last post by:
a2k (9.0.6926) SP-3 Jet 4.0 SP-7 I have a form with combo box field that allows the user to select from the combo box or type in the field value that may or maynot be in the combo box field. In the After Update Event of the combo box field how can I tell if the field value was selected from open combo box or typed in by the user? Thanks, John
2
2170
by: Jeff Mason | last post by:
I'm observing some strange behavior when I use a bound combo box in conjunction with the combo's anchor property. I define a form which contains just a textbox and a combo box. The text box is placed before the combo in taborder, and is there only so the focus will go someplace other than the combo box when the form is displayed. In the form load event, I have the following code to create an arraylist and bind the combo to it: Dim a As...
3
3649
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1" through "Phase 10" (there are 10 Phases I want to sort from) Once the phase has been selected a second combo box would populate.
9
6754
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the second combo to change depending on what values the user selects in the first box, it's just that every time the user changes the first combobox, the second combobox FOR EVERY RECORD goes blank.
2
2443
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to populate the combo (for a list of 2500). Can anybody optimize the code. I tried Duffs devise instead of 'for loop', but no improvement.
6
3674
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
2
7045
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small database I wrote for home, the combo boxes and listboxes no longer display the bound column. For example, on a form I have a combo box based on a table called 'names'. The two columns in the combo box are ID and Surname. The combo box and list box...
0
8478
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...
1
8599
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7439
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
6230
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
5696
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
4225
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...
1
2813
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1810
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.