Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Unanswered: Button Automation

    ,

    I'm writing a script/function to automated putting buttons on the screen.

    I'm running into a problem with var substitutions in my strings, which is necessary to make it run.

    Here is my code:

    Code:
    Function Get_Btn(MyForm)
        Dim Wspace As DAO.Workspace, dbs As DAO.Database, rsDEST As DAO.Recordset
        Dim SQLstmt As String, SrcIdx As Variant, frmName, btnName, btnLabl, N
        Set Wspace = DBEngine.Workspaces(0)
        Set dbs = CurrentDb
        DoCmd.Hourglass True
        frmName = SourceForm.Name
        SQLstmt = "SELECT * FROM qryBTNjoin WHERE ([btn_fnm]='" & frmName & "');"
        Set rsDEST = dbs.OpenRecordset(SQLstmt, dbOpenDynaset)
        With rsDEST
            .MoveLast
            .MoveFirst
            For N = 1 To .RecordCount
                btnName = ![btn_nam]
    '            btnLabl = Eval("SourceForm![" & btnName & "].Caption = ![btn_lab]")
    '            SourceForm![ & btnName & ].Caption = ![btn_lab]
                SourceForm![![btn_nam]].Caption = ![btn_lab]
                Eval("SourceForm![btnName].Visible") = ![btn_vis]
                Eval("SourceForm![btnName].Enabled") = ![btn_enb]
                .MoveNext
            Next N
            .Close
        End With
        DoEvents
        DoCmd.Hourglass False
    End Function
    The lines:
    Code:
    '            btnLabl = Eval("SourceForm![" & btnName & "].Caption = ![btn_lab]")
    '            SourceForm![ & btnName & ].Caption = ![btn_lab]
                SourceForm![![btn_nam]].Caption = ![btn_lab]
                Eval("SourceForm![btnName].Visible") = ![btn_vis]
                Eval("SourceForm![btnName].Enabled") = ![btn_enb]
    Are my attempts to get this right and I've done this sort of substitution before, but right now my mind is blank.

    The query code is:
    Code:
    SELECT tblButtons.btn_id, tblButtons.btn_fnm, tblButtons.btn_nam, tblButtons.btn_lab, tblButtons.btn_sfm, tblButtons.btn_act, tblButtons.btn_vis, tblButtons.btn_enb
    FROM tblButtons LEFT JOIN MSysObjects ON tblButtons.btn_fid = MSysObjects.Id
    WHERE (((tblButtons.btn_nam)<>"") AND ((tblButtons.btn_vis)=Yes) AND ((tblButtons.btn_enb)=Yes))
    ORDER BY tblButtons.btn_fnm, tblButtons.btn_nam;
    The buttons table "tblButtons" is:
    Code:
    Table: tblButtons
    Columns:
    Name      Type           Size        Attributes
    btn_id    Long Integer   4           Fixed Size, Auto-Increment
    btn_fid   Long Integer   4           Fixed Size
    btn_nam   Text           20          Variable Length
    btn_fnm   Text           50          Variable Length
    btn_lab   Text           80          Variable Length
    btn_sfm   Text           50          Variable Length
    btn_act   Text           50          Variable Length
    btn_vis   Yes/No         1           Fixed Size
    btn_enb   Yes/No         1           Fixed Size
      
    Table Indexes
    Name        Number of Fields   Order by       Order
    btn_fid     1                  Self           Ascending
    btn_id      1                  Self           Ascending
    PrimaryKey  1                  btn_id         Ascending
    
    Field descriptions are:
    Code:
    btn_fid  Xref to ID in MSysObjects table
    btn_nam  button name/identifier as used in form
    btn_fnm  form name where button resides
    btn_lab  button label/caption property
    btn_sfm  subform that button calls, if any
    btn_act  subroutine that button calls, if any
    btn_vis  button visible property
    btn_enb  button enabled property
    
    Some help here would be appreciated.

    DBS4M

  2. #2
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Help

    All,

    Is this too complex?

    DBS4M

  3. #3
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Testing

    All,

    I think I may have this one solved, testing a solution now!

    DBS4M

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    First: You cannot get information on a button, or on any other control of a form in the MSysObjects table.
    Second: Eval was not conceived to perform this kind of operation. It may work but it's certainly not the normal way of doing things.
    Third: "var substitutions" is just gibberish.
    Fourth: Your code does not create anything. To create a button on a form, this form must be open in design mode and you have to use the CreateControl method to do so.
    Fifth: The case is closed as far as I'm concerned, it's hopeless.

    Have a nice day!

  5. #5
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Understanding

    Quote Originally Posted by Sinndho
    First: You cannot get information on a button, or on any other control of a form in the MSysObjects table.
    Second: Eval was not conceived to perform this kind of operation. It may work but it's certainly not the normal way of doing things.
    Third: "var substitutions" is just gibberish.
    Fourth: Your code does not create anything. To create a button on a form, this form must be open in design mode and you have to use the CreateControl method to do so.
    Fifth: The case is closed as far as I'm concerned, it's hopeless.

    Have a nice day!
    S,

    Answering you, think you are confused about my intent,

    1. MSysObjects table is refeneced in the join to confirm a valid form, nothing else,
    2. Eval and it's alternative, just really trying to understand it,
    3. Well items 2 & 3 are where the help is needed,
    4. I'm not designing or adding anything to the form, it already exists, I'm just assigning values and functionality to the existing object, which one can do without using "CreateControl". I know I used the term "putting" so understand your confusion. I since decided, because of spacing issues to use a standard sized button, initially declare with .visible = false, and then turn them on as needed on the page. Sorry for not relating that here.
    5. Not closed with me, as I'll master it. Actually have most of this working, just can not assign a function call to the button yet because on my personal limits on item 2 &3.

    Thanks for you input though.

    DBS4M

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I lost interest in this topic as I don't believe it's worth any effort to automate the creation of command buttons. Better/simpler/easier is to just place enough of them on your form and then use code to hide/reveal them as needed.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Same Place

    All,

    I have this one done, with interpret exception, I detailed at:

    http://www.dbforums.com/microsoft-ac...able-save.html

    Sure could use some help on this issue. It is impacting me at several places.

    Thanks!

    DBS4M

  8. #8
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Similar to PHP

    Quote Originally Posted by StarTrekker
    I lost interest in this topic as I don't believe it's worth any effort to automate the creation of command buttons. Better/simpler/easier is to just place enough of them on your form and then use code to hide/reveal them as needed.
    ST,

    Since you and I conversed off-line from this, the attempt is to be able to get menu buttons the way one does in PHP from the DB.

    DBS4M

Posting Permissions

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