Results 1 to 4 of 4
  1. #1
    martingaleh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    22

    controls don't pass procedures consistently

    I have this code:


    Code:
    'In sub form module
    sub button_click()
      me.parent.updateList
    
    'In parent form module
    Public Sub updateList()
        Dim vID As Integer
        Dim vIDS() As String
        
        vID = Me![Grand Unifying Table subform].Form.ID
        'It'd be nice to find a way to ensure that vID is a number, but it doens't really matter
        'List274 is a list box on the parent form.  This assignment normally works, but here, g and h evaluate to null
        g = Me!List274
        h = Me.List274
        'Using set is normally not necessary, but in this case it is
        Set i = Me!List274
        clearListBox (i)
    
    'In normal module
    ' as control normally not necessary, as isn't by ref, necessary here...
    sub clearListBox(byref ctl as control)

    that get's called from a click event on a subform. Normally, when an event on the parent form refers to a control on a mainform,
    g=Me!control works fine
    Here, I need
    set i = Me!List274 because the scope is block scope I supposed, but it's really slow. Like setting i to Me!List274 makes the computer think about it for five seconds.
    Me.Parent.List274 doesn't work because this line executes in the scope of the parent form
    When I hover my cursor over i or Me!List274, its null, but in the immediate window it's Variant/Object/ListBox and when I do ?i.name, it's List274
    Finally, if I add Dim i as listbox, it's nothing in the immediate windows, but changes to ListBox after the set i..., but hovering the cursor over the variable still shows null


    Also passing to down to a procedure in a normal module doesn't work, I get object required even though i is clearly an object.
    I've tried clearListBox (Me!List274) also, but that has failed.
    I removed the "as Control" and it works, but then ctl is null and there is no object
    I've also tried "as Object" to cast it as a base class, but that's failed too.

    Then I tried moving the sub to the parent form module, and it still doesnt' work not matter what.
    Finally, in the parent form module, I added the line set ctl = Me!List274, and it's null with the cursor, but ctl.ListCount etc. works so I can manipulate the ctl as is normal. I'm obviously doing something wrong, but there is nothing on the web to explain this behavior. If the initial control firing the event was on the parent form, none of this would have been an issue

  2. #2
    martingaleh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    22
    I swear, this works as expected

    Instead of:
    clearListBox (i)

    If I do
    clearListBox i
    It will work, regardless if I have
    clearListBox (byref ctl as object)
    or
    clearListBox (byref ctl)

    It's not really the casting that matters, it's whether I use parenthesis or not when calling the function. Can this really be a feature of access?

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    What is the problem, the code is a slow performer?
    I would declare all of my variables and properly instantiate any objects.

    Code:
    dim g as Control
    dim h as Control
    dim i as Control
    set g = Me!List274
     set h = Me!SomeOtherList
     set i = Me!ListControl
     clearListBox i

  4. #4
    martingaleh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    22
    The problem was the parenthesis. The fact that the default action is to not use parenthesis is a big thing, books should emphasize this. .3% of my year was wasted to figure this out. And that it's dog slow. I've done the declaring. I've also tried to batch my record manipulations in a transaction. I'm using sharepoint with local caching. Alas...

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

Similar Threads

  1. Database for procedures
    By Rabastan99 in forum Database Design
    Replies: 1
    Last Post: 10-19-2014, 10:03 AM
  2. Replies: 3
    Last Post: 08-29-2014, 10:57 AM
  3. Event Procedures
    By jlgray0127 in forum Forms
    Replies: 6
    Last Post: 11-04-2011, 02:24 PM
  4. Replies: 6
    Last Post: 08-16-2011, 12:54 PM
  5. Event procedures
    By GIS_Guy in forum Forms
    Replies: 1
    Last Post: 05-11-2010, 02:34 PM

Tags for this Thread

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