Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    126

    Unanswered: Quick question about datatypes, please help

    I am moving a bunch of controls around in an Access report using VBA, and I wanted to generalize

    Code:
    With Me.txt_inv_no
         .Visible = True
         .Top = 510
         .Left = 10695
    End With
    as

    Call SetProperty("txt_inv_no","Top",510)
    Call SetProperty("txt_inv_no", "Left",10695)

    Theoretically, I want it to perform along the lines of this, which I think makes sense, although I understand it could get a little messy
    Code:
    Sub SetProperty(propertyParent As ???, propertyName As ???, propertyValue As ???)
        Me.propertyParent.propertyName = propertyValue
    End Sub
    And eventually, I'd like to get to something along the lines of:

    Call SetProperties("txt_inv_no","Top",510,"Left",10695)

    but I can figure that one out once I understand what is needed to do the first one.



    On a related note, I already have working this function which takes an array of controls and sets the visibility on or off

    Code:
    Sub SetVisibility(VisibleOrNot As Boolean, ControlArray As Variant)
        Dim intI As Integer
        For intI = 0 To UBound(ControlArray)
            ControlArray(intI).Visible = VisibleOrNot
        Next intI
    End Sub
    But I would now like to pass an array of properties about one control instead of changing one property on an array of controls.

    Thank you all for your help.

  2. #2
    Join Date
    Feb 2004
    Posts
    137
    For your SetProperty sub, try this:
    Code:
    Sub SetProperty(propertyParent As String, propertyName As String, propertyValue As Variant)
        Me.Controls(propertyParent).Properties(propertyName) = propertyValue
    End Sub
    For your second idea, something like Call SetProperties("txt_inv_no","Top",510,"Left",10695) is not so feasible because subs and functions typically require a fixed set of criteria parameters.

    For your third idea, passing an array of properties about one control, here is a good example:
    Code:
    Function Control_Enum(Ctrl As Control) As Control
    On Error Resume Next
    
        Dim CT As Long
        Set Control_Enum = Ctrl
        Control_Enum.SetFocus
        For CT = 0 To Control_Enum.Properties.Count - 1
            Debug.Print Control_Enum.Properties(CT).Name; "=";
            Debug.Print Control_Enum.Properties(CT)
            If Err.Number Then Err.Clear: Debug.Print
        Next CT
    
    End Function
    Within a form or report, if you use something like:
    Code:
    Call Control_Enum(txt_inv_no)
    It should print a list of the control's properties and their values in the Debug Window.

  3. #3
    Join Date
    Feb 2004
    Posts
    126
    Thank you! I am going to work on it right now, and this was PERFERCT timing .

    I wish Access had the same type of thing as Crystal Reports where you can define multiple versions of a section i.e. Page header A, Page Header B and just dynamically choose which, or even both, to display. Instead i'm moving around a whole bunch of controls to accomplish the same thing.

    And on an unrelated note, when will the end users ever understand the effort required to produce "simple" reports?

    Thanks again

  4. #4
    Join Date
    Feb 2004
    Posts
    126
    Thanks for your help, you gave me the start that I needed. I was actually able to achieve both goals that I had set out to do.

    1. Following your advice, I was able to get the first one to work:
    Code:
    Sub SetProperty(ctlpropertyParent As Control, propertyName As String, propertyValue As Variant)
        ctlpropertyParent.Properties(propertyName) = propertyValue
    End Sub
    2. I was even able to get the second idea to work. It's actually quite amazing to me , but it's just what I needed. It is able to turn:
    Code:
    With Me.txt_inv_no
          .visible = true
          .top = 500
          .left = 1000
    End With
    into
    Code:
    Call SetProperties(Me.txt_inv_no, "Visible,True,Top,500,Left,1000")
    Here is the code to the second function, it seems so simple!
    Code:
    Sub SetProperties(ctlpropertyParent As Control, strPropertyArray As String)
        Dim varPropertyArray As Variant
        Dim intI As Integer
        
        varPropertyArray = Split(strPropertyArray, ",")
        
        For intI = 0 To UBound(varPropertyArray) Step 2
            ctlpropertyParent.Properties(varPropertyArray(intI)) = varPropertyArray(intI + 1)
        Next intI
    End Sub
    I know all of this may seem unnecessary to some of you, but there is a reason to my madness.

    I have created a report that requires me moving around a lot controls, and as I mentioned in my previous post, this would all be avoided if Access allowed multiple sections. One other way of doing what I'm doing i guess would be to, instead of moving the controls, just create duplicates in teh right places and turn them on or off.

    Maybe I will change all this stuff around once the design is set, although it doesn't seem to be affecting performance, and it's moving about 25 controls on every page of my report. But for design purposes, it is the only way I can make sense of everything i'm doing.

    Thanks everyone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •