Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronizing Combo Boxes Part 1Million 1

Status
Not open for further replies.

onemiland

Programmer
May 29, 2004
18
US
I'm trying to follow other people's examples and also Microsoft's. Help?

Two Comboboxes: Combo1 is Section and Combo2 is Title. There are 5 different Titles in a Section.

' ****tTitle (TABLE)*****
' iTitleID = Primary Key
' Title = name of combobox for Titles
' SM_Title = Name of title for Service Member
' Sec_Title = Name of Sections (5 Sections per title)
' fkeySectionID = (number) for sharing to SectionID (?)

' ****tSection (TABLE)*****
' SectionID = Primary Key
' Section = Name of dropdown for Sections

Me.Title.RowSource = "SELECT SM_Title FROM" & _
" Title WHERE Sec_Title= " & Me.Section & _
Me.Title = Me.Title.ItemData(0)
 
Hmmm.

Are you stating that your code is not working ?...
Code:
Me.Title.RowSource = "SELECT SM_Title FROM" & _
    " Title WHERE Sec_Title= " & Me.Section & _
    Me.Title = Me.Title.ItemData(0)

You need an AND between the two comparisons OR only have one comparison, and the SELECT clause must use the name of the field names for the table on the left side of the equal side.

I am uncertain about your references to your combo boxes. Me.Title.ItemData(0) is a format I am not familiar with for referencing a combo box. If you are in the second combo box, selecting a title, and the combo box name is Combo1 for section and Combo2 for title, a more typical way is...
Me.Combo1.Column(n) where Column(n) references a specific column in the select statement in the Section combo box.

For example, if the SELECT statement for Me.Combo1 was...
SELECT Sec_Title From...
Then you can reference the value selected in the first combo box as Me.Combo1 or Me.Combo1.Column(0)


Moreover, if the section and title are string or text variables, they need to be encapsualted within quotes when referenced on the right side of the comparison.

There is are various solutions. Here is one to consider - my coding style will differ from yours, and I am making some assumptions...
Code:
Dim strSQL As String, strQ As String
strQ = Chr$(34)  'double quote
strSQL = "SELECT SM_Title FROM Title WHERE Sec_Title = " & strQ & Me.Combo1 & strQ
Me.Title.RowSource = strSQL

I am assuming...
- Combo1 has the already selected the section
- Section variable is in the first field of the Select statement
- Section is a text string

Note that if there is an error in the syntax, Access will complain. If you do not have error checking, Access will high light the line causing the error. By using a string variable for the select clause, you can print the string to check for syntax errors.

How?
CTRL-G to bring up the debugger or immediate window and then type...
? strSQL

Hope this helped a bit.
Richard
 
Thanks for your prompt reply. I'll read it over and give it a try. Hey...that rhymes!

 
I am sooo lost here. Do I have the tables right (as described above)? Do I need a relation from SectionID (PrimaryKey) to fKeySectionID and is there some queries that need to be made?

I guess I seen so many examples that I have blended in all of them and lost myself.

So as I described above. Two tables. Two comboBoxes, Combo1 (Section) has a AfterUpdate with the Code you showed me?

Thanks. Lost in Seattle with Cboboxes
 
HAve you read the FAQ area for Combo ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
willir

Me.Title.ItemData(n) is a mechanism for returning the n th item in the bound column of the dropdown list of the combo box

So
Title = Title.ItemData(0)
sets the default value thats shown in an combo box to the first row of the rowsource.
( All those Me. s are unnecessary )



'ope-that-'elps.

G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Graham

I have always used .column(x) instead of ItemData(x)

Thanks for the enlightenment. Star for you.
 
Arrrh yes willir

You can think of .ItemData(x) as a simplified version of .Column(x)



Eg.
.Column(c,x)
The c representing the column index
The x representing the row number in the rowsource

so .ItemData(n) is exactly the same as .Column(b,n)

where b is the BOUND COLUMN.

.Column is much more flexible.
but if you are not sure of which column is the bound column then you can use .ItemData



'ope-that-'elps.


G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top