Results 1 to 9 of 9
  1. #1
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64

    Query not running right in subroutine

    I think this is a weird one. I've got a query doing this same thing working fine in another situation, but I get the attached error every time my subroutine tries to call this query. I tried it directly in the subroutine and now I've tried having the subroutine call the query. I get this error every time.
    Click image for larger version. 

Name:	Access Error.jpg 
Views:	7 
Size:	22.4 KB 
ID:	10925
    This is the subroutine:



    Code:
    Private Sub Check696_Click()
    If Check696 = True Then
    Form_Employees.FilterOn = True
    Employee_Select.RowSource = [Employees_Current]
    Else
    Form_Employees.FilterOn = False
    Employee_Select.RowSource = [Employees_All]
    End If
    Employee_Select.value = Null
    End Sub
    Here is the query:
    Code:
    SELECT Employees.ID, [Employees].[First_Name] & " " & [Employees].[Last_Name] AS Name, Employees.Last_Date
    FROM Employees
    WHERE (((Employees.Last_Date) Is Null))
    ORDER BY [Employees].[First_Name] & " " & [Employees].[Last_Name];
    I suspect my problem/solution is with quotations, but I'm stuck.

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    have you tried breaking down the query. Like remove the order by then name field and see what works and what doesn't?

  3. #3
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    is your query code in a string or a normal query object?

    if it is in a string then you need to change the " double quotes to singles '.

    I would also remove tHe ( ) in the where clause too.. WHERE [LAST_DATE] IS NULL

    LAST_DATE needs [] around it that might be your issue as well..

    it is tough when you add special chars to field names because they have to wrapped everywhere.. with []'s

  4. #4
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64
    Another thought - what I'm doing here is using a checkbox control to turn on and off the forms filter that filters out former employees or shows all. I'm using a combo box control for a navigation. Can I just tie the rowsource of the combo control to the forms current recordset so one updates the other?

  5. #5
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    Sure you can that's easy to do

  6. #6
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64
    It's definitely in the first line SELECT statement. When I hit debug, it opens to that line. When I enter that line by itself, I get a "expected end of statement" error usually.

  7. #7
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64
    Quote Originally Posted by alcapps View Post
    Sure you can that's easy to do
    Well thanks ya big tease...

    So if I set the on click or on focus event for my combobox something like, "Set Me.Recordset = Forms!Form1.Recordset" then what would I use in my Row Source property? "SELECT Employee_ID from Me.Recordset"?

  8. #8
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64
    For what it's worth, I created the Employees_Current and Employees_All queries, then used a query in my rowsource property plucking the employee ID's and names from those queries and it works just fine. It's a little convoluted and not very eloquent and I think there's got to be a better way to do this in VBA, but this one fixed the problem. But if you could help me out with that recordset method instead, it would be more universally useful on my other forms and wouldn't have to build queries to query queries to get this done...

  9. #9
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    can you put a database together that has the data and form in it so that we can see the issue and maybe correct it and post it back?

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

Similar Threads

  1. Query with a running sum
    By is49460 in forum Queries
    Replies: 3
    Last Post: 09-07-2013, 11:11 PM
  2. Replies: 1
    Last Post: 10-29-2012, 11:24 PM
  3. Calling Access VBA subroutine from an Excel VBA subroutine
    By richard_yolland in forum Programming
    Replies: 0
    Last Post: 02-16-2011, 11:30 AM
  4. Referencing a Subroutine
    By Lockrin in forum Programming
    Replies: 1
    Last Post: 02-26-2010, 10:09 AM
  5. Passing a form name to a subroutine
    By trb5016 in forum Programming
    Replies: 0
    Last Post: 02-01-2010, 12:03 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