Results 1 to 8 of 8
  1. #1
    nika.duncan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    36

    Cascading Combo Box Issues

    Hey,

    I am trying to create cascading combo box where when I select the make of a vehicle only models for that make will appears. The code below is what was used. When I select the make on the form "frmVehicleDetails" and click on the dropdown for the model I receive the error "Syntax error in date in query expression 'tblVehicleModel.VehicleModel#". Attached is the file "FuelManagement1.zip" I am working with any help would be appreciated in resolving this issue.


    Code:
    Option Compare Database
    
    Private Sub cboVehicleMakeName_AfterUpdate()
    
    
    'Set the Vehicle Modelcombo box to be limited by the selecetd Vehicle Make.
    Me.cboVehicleModel.RowSource = "SELECT tblVehicleModel.VehicleModel#, tblVehicleModel.VehicleModel FROM tblVehicleModel " & _
        " WHERE VehicleMake# = " & Nz(Me.cboVehicleMakeName) & _
        " ORDER  BY VehicleModelName"
    
    
    Me.cboVehicleModel = Null
    
    
    EnableControls
    
    
    
    
    End Sub
    
    
    Private Sub EnableControls()
    
    
    'Clear the combo bozes
    If IsNull(Me.cboVehicleMakeName) Then
        Me.cboVehicleModel = Null
    End If
     
    End Sub
    
    
    Private Sub Combo6_AfterUpdate()
    'Set the Vehicle Modelcombo box to be limited by the selecetd Vehicle Make.
    Me.Combo8.RowSource = "SELECT tblVehicleModel.VehicleModel#, tblVehicleModel.VehicleModel FROM  tblVehicleModel " & _
        " WHERE VehicleMake# = " & Nz(Me.Combo8) & _
        " ORDER  BY VehicleModel"
    
    
    Me.Combo8 = Null
    
    
    EnableControls
    End Sub
    
    
    Private Sub Form_Load()
    
    
    'When the form loads, enable/disable the combo boxes.  Combo boxes are only enabled if the preceeded combo box has a value.
    EnableControls
    
    
    End Sub

    Thanks.
    Nika
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Possibly the # which is used to surround dates?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Any field names containing spaces and\or special characters need to be enclosed in square brackets:
    SELECT [VehicleModel#], VehicleModel FROM tblVehicleModel.....

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Try the attached db:
    BTW I would advise against the use of special characters like # in the naming of any Access object.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    nika.duncan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    36
    Thanks I will go through and edit the field names.

  6. #6
    nika.duncan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    36
    Hey,

    I need help in correcting the code behind the form. I corrected the issues with the field names but I am having another problem. When I select the make and try selecting the model I get a message " Enter Parameter Value" as shown below once I entered the number for the make the models are listed.


    Click image for larger version. 

Name:	ParameterValueRequest.jpg 
Views:	21 
Size:	33.7 KB 
ID:	50015
    Please see the code inserted below also attached is the database
    Code:
    Private Sub cboKingdomID_AfterUpdate()
    
      ' Set the Phylum combo box to be limited by the selected Kingdom
      Me.cboPhylumID.RowSource = "SELECT tblPhylum.PhylumID, tblPhylum.PhylumName FROM tblPhylum " & _
         " WHERE KingdomID = " & Nz(Me.cboKingdomID) & _
         " ORDER BY PhylumName"
      Me.cboPhylumID = Null
      
      EnableControls
      FilterSpeciesList
      
    End Sub

    Any help will be appreciated.

    ThanFuelManagement2.zipks
    Nika
    FuelManagement2.zip

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    according to your db the code behind cboVehicleMakeName_AfterUpdate is

    Code:
    'Set the Vehicle Modelcombo box to be limited by the selecetd Vehicle Make.
    Me.cboVehicleModel.RowSource = "SELECT tblVehicleModel.VehicleModelNum, tblVehicleModel.VehicleModel FROM tblVehicleModel " & _
        " WHERE VehicleMakeNum = " & Nz(Me.cboVehicleMakeName) & _
        " ORDER  BY VehicleModelName"
    You don't have a field called VehicleModelName in tblVehicleModel (suspect this should be VehicleMakeName)

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If you want to fiilter Model by VehicleMakeNum then need to include VehicleMakeNum in Make combobox RowSource.
    SELECT VehicleMakeNum, VehicleMakeName FROM tblVehicleMake ORDER BY VehicleMakeName;

    Then RowSource for Model:
    SELECT VehicleDetailNum, VehicleModelName, VehiclePlate FROM tblVehicleDetail WHERE VehicleMakeNum = cboVehicleMakeName ORDER BY VehicleModelName, VehiclePlate;

    And in VBA no need to set RowSource, just:
    Me.cboVehicleModel.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cascading Combo Box to List Box Issues
    By waves678 in forum Forms
    Replies: 8
    Last Post: 09-14-2021, 07:20 AM
  2. Cascading combo requery issues
    By ccook241 in forum Database Design
    Replies: 5
    Last Post: 10-30-2018, 06:38 PM
  3. Replies: 1
    Last Post: 02-27-2014, 03:43 PM
  4. Cascading Combo Box and Subform Issues
    By RossIV in forum Forms
    Replies: 13
    Last Post: 07-18-2013, 09:16 AM
  5. Access 2003 - cascading combo box issues
    By agripa86 in forum Access
    Replies: 1
    Last Post: 08-12-2011, 06:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums