Results 1 to 7 of 7
  1. #1
    mariost is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Posts
    9

    Upgrade to 2007-2013 Access crashes of form_CLose with array of controls

    Dear all,

    I have a very peculiar issue. It is about an Access application (*.mdb) which among others have a calendar form with 14*20=280 textboxes for scheduling several production lines (i.e. 20 machines for 14 days). In order to add events to each control I used an array of controls which I declared as shown below. The form works fine and events are raised as expected.

    Recently I had to upgrade the application to Access2007-2013 version (*.accdb). The upgrade went OK and the complete application seems to work fine and so is the calendar form. The only problem is that when I close the calendar form the whole application crashes. What is more confusing is that this does not happen on my development machine (Windows 10, MS access 2007 and MS access 2013) but only to the clients of the customer (Windows 8 or Windows 10, MS access 2007 and 2013). The line of code that creates the problem is highlighted in red. If I comment it out the applications does not crashes but of course the events are not created.

    The other thing I noticed and I am not sure if it is an issue is that my developent machine is 32-bit where the client's machines are 64-bit.


    I am really puzzled to what the problem is. Can any one help.



    Code:
    Dim arrCmd(280) As New myClass
    
    
    Sub AddTextboxesToCollection()
        
    Dim arrCnt As Integer
    Dim i As Long
    Dim j As Long
    
    
    arrCnt = 0
    
    
    
    
    '* add textboxes to collection - this is to capture events in textboxes
    
    
    For i = 0 To 13
        For j = 0 To 19
            Set arrCmd(arrCnt).ctl = Me.Controls("Date" & i & "Machine" & j)
            arrCnt = arrCnt + 1
        Next
    Next
    
    
    End Sub
    MyClass class module



    Code:
    Option Compare Database
    Option Explicit
    
    
    Private WithEvents mCtl As TextBox
    
    
    Public Property Set ctl(ByVal vNewValue As TextBox)
    
    Set mCtl = vNewValue
    mCtl.OnDblClick = "[Event Procedure]"
    mCtl.OnClick = "[Event Procedure]"
    
    
    End Property
    
    
    Private Sub mCtl_DblClick(Cancel As Integer)
     
     Call ShowSchedulingExtraItems(mCtl)
        
        
    
    
    
    
    End Sub
    
    
    Private Sub mCtl_Click()
    
    
     Call ShowPOrderDetails(mCtl)
    
    
    
    
    End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    what is the value of vNewValue before you attempt to set it as a control. (debug.print vnewvalue). I suspect the value is not getting passed correctly.

    You may want to try something more like

    (assuming vNewValue is the name of a text box or list box or something)

    Code:
    with me.controls(vnewvalue)
         .ondblclick = "[Event Procedure]"
         .onclick = "[Event Procedure]"
    end with

  3. #3
    mariost is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Posts
    9
    Hi rpeare,

    thanks for responding. You are right, the vNewValue is passed as Null. But somehow it works in Access 2003-2007 and creates no problem. It's only when I upgrade to 2007-2013 that crashes on Form_Close.

    Also, where do I use the code you recommended? In Myclass file? I cannot use Me.Controls in MyClass file.

    Is there any other way I can create this array of controls and assign events on them?

    Marios

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    what happens if you encapsulate to check for a null value


    i.e.

    Code:
    if len(trim(vnewvalue)) > 0 then
         'insert code from previous post here
    endif
    so this section of code would be skipped if vnewvalue is blank

  5. #5
    mariost is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Posts
    9
    Hi rpeare,

    I am not sure how this helps. For some reason vNewValue is always Null but the events are raised. So even if checking for Null will not help. Also in the proposed code you have Me.Controls which I cannot use in the Class file. This code is not on the form, is in the Class file.

    Can you please propose the right way of declaring an array of controls in a Form and create events for that controls without having to write code for each of the control. I found this approach in a forum and it worked straight away but obviously is not the right way of doing things.

    Marios

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You can (should be able to) skip the with statement and use what you have and still check for zero length (not a null value).

    Code:
    Public Property Set ctl(ByVal vNewValue As TextBox)
    if len(trim(vnewvalue)) > 0 then
         Set mCtl = vNewValue     
         mCtl.OnDblClick = "[Event Procedure]"
         mCtl.OnClick = "[Event Procedure]"
    
         '.... the remainder of your code in here
    endif
    If instead you want to cycle through controls on a form you can do

    Code:
    Public Function CycleThrough(sformname)
    dim ctl as control
    
    for each ctl in forms(sformname).controls
         'debug.print ctl.name
         'note the above debug will list *all* controls
         'typically I will use the TAG property to create subsets of controls I care about i.e. DE in the TAG property for data entry fields so you can do something like
         if instr(ctl.tag, "DE") then
              debug.print "data entry field: " & ctl.name
         endif
    next ctl
    As a side note, I tend to write functions and write them as generically as possible so for instance if I have a form named table tblEmployees, the form relating to data entry is frmEmployees, and if I have a command button open that form it's named cmdEmployees, so in the 'on click' event of the button I can have some generic code like docmd.openform replace(screen.activecontrol.name, "cmd", "frm") that works regardless of which button I attach it to. If you have a form with a ton of controls that all have similar functions I would attempt to economize your code with functions rather than having the same code repeated across controls

  7. #7
    mariost is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Posts
    9
    Hi,

    with this code the events are simply not raised because vNewValue is NULL. Is it something wrong with the way I am instantiating the class and that's why vNewValue is always zero length? As I told you, if I don't check for vNewValue the code works fine in Access 2003-2007.

    Sorry, obviously I am not getting what you are trying to tell me.

    What I am trying to achieve is to have events raised for 280 textboxes in a form without having to write all event separately. Is there any other way to do this without having a Class? Can I do it in the form?

    Marios

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

Similar Threads

  1. Replies: 5
    Last Post: 01-10-2016, 05:00 AM
  2. Replies: 1
    Last Post: 06-25-2015, 05:24 AM
  3. Replies: 6
    Last Post: 05-27-2015, 09:16 AM
  4. 2007 to 2013 upgrade
    By gar in forum Access
    Replies: 1
    Last Post: 02-23-2013, 08:37 AM
  5. Replies: 5
    Last Post: 05-19-2010, 12:05 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