Results 1 to 5 of 5
  1. #1
    Johnny Chow is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    4

    combo box problem

    Hi


    any one can help me, I run sql statement one, there is no respond, second and third sql statement, there is an error 2580 but I run the sql statement four, there is no problem, I want to use the value of the combo box to get what I want. please help. Thanks




    Private Sub Combo7_AfterUpdate()


    Dim conn As ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim sql As String
    Dim yy As Date


    yy = Me.Combo7


    Set conn = CurrentProject.Connection


    'sql = "select [Catagoey],[Disbursements],[Sum of Total]from [Disbursements Sum Query] where [Date By Year] = #" & yy & "# "
    'sql = "select [Catagoey],[Disbursements],[Sum of Total]from [Disbursements Sum Query] where [Date By Year] = Me.Combo7.Value"
    sql = "select [Catagoey],[Disbursements],[Sum of Total]from [Disbursements Sum Query] where [Date By Year]" = Me.Combo7.Value
    sql = "select [Catagoey],[Disbursements],[Sum of Total]from [Disbursements Sum Query] where [Date By Year] = 2018"


    Me.RecordSource = sql


    Set rst = Nothing


    End Sub

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    First thing you should do when trying to debug an Sql statement is to add a debug.Print after the construct. That way you can see what it resolves to.
    You also need to place the variable outside the sql statement and delimit it as needed.
    What column in the combobox is DateByYear? Whats the datatype?

    if it is text it should look something like below

    Code:
    sql = "select [Catagoey],[Disbursements],[Sum of Total]from [Disbursements Sum Query] where [Date By Year]  =  '" & Me.Combo7.column(?)  & "'"
    
    Debug.Print sql
    You should eliminate the spaces in your field and object names.
    Not sure what the ADO references are for so i wont comment on that.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Year alone is not a date value, it is only a number. The = sign must be within quote marks and then concatenate reference to combobox.

    sql = "select [Catagoey],[Disbursements],[Sum of Total] from [Disbursements Sum Query] where [Date By Year]=" & Me.Combo7

    I am guessing Catagoey is really intended to be Category. Might consider correcting the field name in table.

    Also see no reason for the recordset code and agree about no spaces in naming convention - nor punctuation/special characters (underscore only exception).

    Instead of setting RecordSource, could set Filter and FilterOn properties.
    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.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  5. #5
    Johnny Chow is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2018
    Posts
    4
    I have solved the problem because your help, thanks very much!

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

Similar Threads

  1. Combo Problem
    By drunkenneo in forum Programming
    Replies: 1
    Last Post: 07-04-2013, 03:17 PM
  2. Combo Box Problem
    By dccjr in forum Access
    Replies: 2
    Last Post: 11-13-2012, 09:48 PM
  3. Combo box problem
    By Lowell in forum Forms
    Replies: 2
    Last Post: 03-19-2012, 06:40 PM
  4. Combo box problem
    By dkatorza in forum Access
    Replies: 2
    Last Post: 11-09-2011, 06:19 PM
  5. Combo box look-up problem
    By Samdaman in forum Forms
    Replies: 0
    Last Post: 12-14-2009, 02:54 PM

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