Results 1 to 5 of 5
  1. #1
    mlrucci is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    109

    Invalid Qualifier VBA

    Good afternoon, I am fairly new to vba and am attempting to advance my programming. What I would like to do is declare my variables when referring to subforms within my navigation forms. I cannot seem to figure out how to declare my path to control using Dim. Below is a simple example. When using this, I get compile error invalid qualifier. Insight would be helpful. What I am attempting to do is



    [Forms]![frmNavMain]![frmNavMain].[Form]![frmNavInvoices].[Form].lstSub.RowSource = "qrySub_Lost"

    Alone works great, after trying to move to declaring the variables, not so great.


    Code:
    Private Sub cboInvoiceMonth_Exit(Cancel As Integer)Dim strPath As String
    strPath = "[Forms]![frmNavMain]![frmNavMain].[Form]![frmNavInvoices].[Form]"
        'update list with missing subscriptions
        strPath.lstSub.RowSource = "qrySub_Lost"
        
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,973
    You're trying to assign an object property to a string. Declare the variable as an object, not a string - in this case, a control. Try

    Code:
    Private Sub cboInvoiceMonth_Exit(Cancel As Integer)
    Dim ctl As Control
    
    Set ctl = [Forms]![frmNavMain]![frmNavMain].[Form]![frmNavInvoices].[Form].lstSub
    
    ctl.RowSource = "qrySub_Lost"
        
    End Sub
    EDIT - if you need to, set a variable to a form so that your reference is to the parent object. That way you can use the same variable when referencing several controls on the form.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  3. #3
    mlrucci is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    109
    Quote Originally Posted by Micron View Post
    You're trying to assign an object property to a string. Declare the variable as an object, not a string - in this case, a control. Try

    Code:
    Private Sub cboInvoiceMonth_Exit(Cancel As Integer)
    Dim ctl As Control
    
    Set ctl = [Forms]![frmNavMain]![frmNavMain].[Form]![frmNavInvoices].[Form].lstSub
    
    ctl.RowSource = "qrySub_Lost"
        
    End Sub
    EDIT - if you need to, set a variable to a form so that your reference is to the parent object. That way you can use the same variable when referencing several controls on the form.

    Thank you very much for your reply. I attempted to define the variable as stated and placed it in the vba (even copied paste) and I am returning "object doesn't support this property or method" Ideas/Thoughts?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,973
    First have to be sure your chain of references is correct because a listbox does have a rowsource property and you're not trying to use a method. When I need to validate I use the Immediate window and check each object in the chain of references using the name property. When your form is loaded in your navigation form you make an inquiry in the immediate window by starting with a question mark, typing the reference then pressing Enter. If you were to start with the navigation subform control name on the main form then

    ?[Forms]![frmNavMain]![frmNavMain].Name
    If you get the name you expect then the reference up to that point is correct. If not, you get an error. If OK, go one level deeper and recheck:

    ?[Forms]![frmNavMain]![frmNavMain].[Form].Name

    I expect you will find that there is an issue.

    Most of all, post your code, not the example given. It helps to remove doubt about possible syntax errors. Another option is to copy, compact, zip your db and post it here.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  5. #5
    mlrucci is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    109
    Your are 100% correct. I tried it but forgot I put the target control one form deeper. That was my fault. Thank you for all your help. Works like a charm!

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

Similar Threads

  1. Invalid use of null?
    By snipe in forum Programming
    Replies: 12
    Last Post: 05-12-2015, 04:53 PM
  2. Replies: 5
    Last Post: 07-22-2014, 06:58 AM
  3. Replies: 7
    Last Post: 08-28-2011, 02:07 PM
  4. Invalid use of me
    By kman42 in forum Access
    Replies: 1
    Last Post: 04-28-2011, 12:40 PM
  5. Invalid Operation
    By ScottG in forum Forms
    Replies: 0
    Last Post: 11-14-2006, 02:05 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 - Senior Forums