473,513 Members | 7,598 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 1832
"Erich Kohl" <ek***@sbcglobal.net> wrote in message
news:e6********************************@4ax.com...
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***@sbcglobal.net> wrote in message
news:9e********************************@4ax.com...
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_AfterUpdate()

On Error GoTo Err_Handler

Dim lngConID As Long

lngConID = CLng(Nz(Me.cboConID.Value, 0))

If lngConID > 0 Then
With Me.RecordsetClone
.FindFirst "ConID=" & CStr(lngConID)
If .NoMatch Then
MsgBox "Cannot locate record" & vbCrLf & _
"ConID=" & CStr(lngConID), _
vbExclamation
Else
Me.Recordset.Bookmark = .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
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_AfterUpdate()

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***@sbcglobal.net> wrote in message
news:de********************************@4ax.com...
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_AfterUpdate()

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!ConID, 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***@sbcglobal.net> wrote in
news:de********************************@4ax.com:
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_AfterUpdate()

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!ConID, 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
4289
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
4247
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...
6
3536
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. ...
2
2147
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...
3
3624
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"...
9
6741
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...
2
2427
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...
6
3667
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
7016
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...
0
7153
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
7373
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,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7519
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...
0
4743
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...
0
3230
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
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 ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.