By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

Problem Syncing 2 Combo Box, I can't determine why my after event code is not working

P: 9
Hi,

I'm very new to Access and having great difficultly trying to sync 2 combo boxes. I have been using The MS Access help for this issue. I have one Combo box titled sboPackageNumber and and another titled sboPackageDescription. My Table the data is taken from is called Sheet1. The columns on the table are Package Number and Package Description.

My code is as follows:


Expand|Select|Wrap|Line Numbers
  1. Sub Me.sboPackageDescription.RowSource = "SELECT Package_Description FROM" & _
  2.    " Sheet1 WHERE Package_Number = " & Me.sboPackageNumber & _
  3.    " ORDER BY Package_Description"
  4. Me.sboPackageDescription = Me.sboPackageDescription.ItemData(0)
  5.  
  6. End Sub

I'm currently getting Compile error : Expected:identifier

Thanks in advance.
3 Weeks Ago #1

✓ answered by zmbd

Sub Me.sboPackageDescription.RowSource = "SELE (...)
is malformed!!!

At best your code should appear to be something like:
Expand|Select|Wrap|Line Numbers
  1. Sub yourProcedureNameHere() 
  2. '
  3. 'You should build your rowsource string first
  4.   Dim myRowSQL as String
  5.   myRowSQL = _
  6.     "SELECT Package_Description FROM" & _
  7.        " Sheet1 WHERE Package_Number = " & _
  8.        Me.sboPackageNumber & _
  9.        " ORDER BY Package_Description"
  10. 'that way you can insert the following, <Ctrl><g> and see the result to check for proper form.
  11. '  Debug.Print myRowSQL
  12. '
  13.   Me.sboPackageDescription.RowSource = myRowSQL
  14. '
  15.   Me.sboPackageDescription.ItemData(0)
  16. '
  17. End Sub 
Take a read thru this insights article... I think this may be along the train of thought you're following:
Bytes > Sitemap > Microsoft Access / VBA Insights>Cascading Combo/List Boxes

I'll also send you a boilerplate with, imho, some better resources for things Access/VBA :) Bytes.com>InBox

Share this Question
Share on Google+
2 Replies


zmbd
Expert Mod 5K+
P: 5,397
Sub Me.sboPackageDescription.RowSource = "SELE (...)
is malformed!!!

At best your code should appear to be something like:
Expand|Select|Wrap|Line Numbers
  1. Sub yourProcedureNameHere() 
  2. '
  3. 'You should build your rowsource string first
  4.   Dim myRowSQL as String
  5.   myRowSQL = _
  6.     "SELECT Package_Description FROM" & _
  7.        " Sheet1 WHERE Package_Number = " & _
  8.        Me.sboPackageNumber & _
  9.        " ORDER BY Package_Description"
  10. 'that way you can insert the following, <Ctrl><g> and see the result to check for proper form.
  11. '  Debug.Print myRowSQL
  12. '
  13.   Me.sboPackageDescription.RowSource = myRowSQL
  14. '
  15.   Me.sboPackageDescription.ItemData(0)
  16. '
  17. End Sub 
Take a read thru this insights article... I think this may be along the train of thought you're following:
Bytes > Sitemap > Microsoft Access / VBA Insights>Cascading Combo/List Boxes

I'll also send you a boilerplate with, imho, some better resources for things Access/VBA :) Bytes.com>InBox
3 Weeks Ago #2

P: 9
Thanks very much for your help and for taking the time to reply!
3 Weeks Ago #3

Post your reply

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