Results 1 to 4 of 4
  1. #1
    TheDeceived is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    8

    Custom Functions

    A form I have designed has a subform embedded within it that changes depending on what button a user presses. There are three options that the user can press, and upon pressing one, it changes the SourceObject to another form within the same database, re-sizes it to that form and finally makes it visible to the user.

    There will be a lot of this going on throughout the use of this database and rather than having to copy and paste the same code over and over again into each button_click event, I'd like to build a function/sub with parameters that can change which form it's referencing for the SourceObject and height.

    For example, here's the code I'm currently using for a button press:

    Code:
    Private Sub Button1_Click()
    
       Me.childFrame.Height = Form_Name.Detail.Height
       Me.childFrame.SourceObject = "FormName"
       Me.childFrame.Visible = True
    End Sub
    I'd like to create a function like the one below that I can call each time that will change the childFrame, Form_Name and "FormName" properties of the three lines called above. Something like:

    Code:
    Public Function RefreshSubform(childFrame As ???, Form_Name As ???, FormName As String)
    
       Me.childFrame.Height = Form_Name.Detail.Height
       Me.childFrame.SourceObject = FormName
       Me.childFrame.Visible = True
    End Function
    That way I can then just call the one line feeding in my chosen variable names:

    Code:
    Private Sub Button1_Click()
    
       RefreshSubform childA, formA, formNameA
    End Sub
    However, I have no idea what data types these variables need to be, never mind if this is actually possible.



    Any help would be highly appreciated

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    IMO, this may give you a headache later on. How many possibilities are there?

    If there aren't a million, I would seriously consider creating a form object for every possibility. (Subforms ARE forms too). This technique would allow you to get all of your code writing concerns down to either one small loop or several short line of VISIBLE property code. Such as:
    Code:
    function ShowSubForm(fName, SubfName as string, Criteria as string)
    
    IF 'criteria THEN
    
       forms(fName).controls.(AltSubfName1).visible = false
       forms(fName).controls.(AltSubfName2).visible = false
       forms(fName).controls.(SubfName).visible = true
       forms(fName).requery
    
    END IF
    
    end function

  3. #3
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,170
    Hi,

    you could use a parameters table that states the name of the form, the dimensions ect. . So for each form you only would have to give the name (or Id) from the subform and all other parameters are tertrieved from that table. Disadvantage: each time you create a naw subform, you'll have to create a new record in the parameters table, advantage: when something changes, you don't have to change the code, only the record in the table.

    gr
    NG

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by NoellaG View Post
    Hi,

    you could use a parameters table that states the name of the form, the dimensions ect. . So for each form you only would have to give the name (or Id) from the subform and all other parameters are tertrieved from that table. Disadvantage: each time you create a naw subform, you'll have to create a new record in the parameters table, advantage: when something changes, you don't have to change the code, only the record in the table.

    gr
    NG
    In a situation like this, code would mostly likely never have to be changed because the scope of differences will always be the arguments that are passed to the universal function.

    and you are right about the table as well. As a matter fact, Microsoft introduced it in the Northwind Example using criteria strings. Another downside to that is the fact that you'll always have to look up the data to use, whereas with parameters only, it takes no memory to store it in a form property.

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

Similar Threads

  1. sum functions
    By trippers in forum Queries
    Replies: 2
    Last Post: 08-04-2010, 07:09 PM
  2. Delete and Dirty functions
    By Evgeny in forum Programming
    Replies: 3
    Last Post: 05-03-2010, 02:39 PM
  3. Functions
    By jamin14 in forum Programming
    Replies: 1
    Last Post: 03-25-2010, 08:16 AM
  4. Help with functions / procedures
    By curnil in forum Programming
    Replies: 3
    Last Post: 03-09-2010, 05:41 PM
  5. Multiple IIF functions possible?
    By Northgate in forum Access
    Replies: 0
    Last Post: 10-08-2008, 01:11 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