Results 1 to 6 of 6
  1. #1
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60

    VBA Function problem

    I have done a bit with VBA now, but just recently started trying to clean up my code and making functions rather than duplicating the code. I have naturally run into a few synax problems on the way.

    The main problem that I keep having problems with is the requery.

    One of the chunks of code had Subform.requery

    Now when I try to do that, it says "object required".

    I have tried passing "subform" as a variable to the function, with the same result.

    Any idea how I can do this?



    Thanks

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You could try the following:

    me.subformcontrolname.requery

    This implies that the code fires from the main form

  3. #3
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60
    thank you.

    that worked when I passed me as a variable to the function.

    so in the function it was:

    strMe.subName.Requery

    Thanks again!

  4. #4
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    OK, I'm glad you got it working, but I don't quite understand how. The "me." in
    me.subformcontrolname.requery

    is just a shortcut for referencing the form from which the code is executed.

  5. #5
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60
    I really don't get how or why.

    when I try:

    me.subformname.requery

    it errors: "invalid use of me"

    It has given me this error every time I have tried using me in a function. I could be doing something totally wrong, i really don't know.

    so my function worked like this

    to define:

    Code:
     
    Function fncName(strMe)
    strMe.subformname.Requery
    End Function
    And to call the function:

    Code:
    Call fncName(Me)

    Anyway, thanks again. That stuff drives me nutts.

  6. #6
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Your function does not say whether it is public or private. Is the function in its own module (i.e. a public function), unrelated to a form? If so, then the "me." shortcut will not work, you would have to pass the entire form reference to the function. Generally, if I need to requery a subform, I just use a private procedure/function of the form.

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

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  2. dlookup function problem
    By bdaniel in forum Programming
    Replies: 3
    Last Post: 04-26-2010, 05:55 AM
  3. Help with AVG function
    By techexpressinc in forum Reports
    Replies: 1
    Last Post: 03-23-2010, 07:47 AM
  4. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  5. I have Problem in processing Dlookup Function
    By Katada in forum Programming
    Replies: 2
    Last Post: 04-23-2006, 12:07 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 - Senior Forums