Results 1 to 8 of 8
  1. #1
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104

    Capture a form's Open instance to a table

    Easy to explain, is it easy to capture via VBA? "FrmOpenMe" opens, then magically capture form name "FrmOpenMe" to write "FrmOpenMe" to a table, with date/time stamp and Coordinator's payroll number...



    I'd like to capture the form name on the Event Open occurrence of any form, and insert that into a table. Just not sure how to create this universally, to capture the form name when run from a function (module). I currently have a function called FormLoad which executes some basic stuff when fired. I'd like to add a bit more to capture the form name of the form being opened, and update a table with the latest instance of the user's 'form' activity.

    thanks in anticipation everyone

    Pete

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd create a public function that accepted the form name as a parameter, then call it from each form's open event:

    FunctionName Me.Name
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    Thanks Paul, great idea, I just have no clue how to get the function to accept the parameter! Me.Novice at that bit!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This should get you started:

    http://www.baldyweb.com/Function.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    Thanks for the reply Paul, but that doesn't answer or help (as I am a little bit less novice that that stage)

    I was hoping for a line of code that does what you suggest and be able to modify myself to insert into the Function 'FormLoad' looking something like this (bad) example:

    Public Function FormLoad()

    'do my first bits first
    If.. then
    do this
    End if

    CODE The Bit I Need! The code to capture the name of the form I just opened, use it as a reference, and then go to the next part

    'next part

    Run SQL statement to write that Form name to a table 'I can do this bit as long s I know what the Form Name is captured as

    End Function

    I appreciate that you are approaching this in a way to help educate people like me to learn (and get better) from your instructions, but it's baffling me right now

    Sorry Paul, but if that explains what I need satisfactorily, can you help with the intermediate code?

    cheers
    Pete

  6. #6
    evander is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    As pbaldy explained, you need to create a public subprocedure or function and refer to this function in the Form_Open event of an Access form. Creating subprocedures and functions is considered a separate skill itself, so you need to read books on this topic to further improve your programming skills.

    Code:
    Public Sub RecordForm (ByVal FormName as String)
         DoCmd.SetWarnings False
         DoCmd.RunSQL "INSERT INTO tblForms (FormName) VALUES (" & ''" & FormName & "')"
         DoCmd.SetWarnings True
    End Sub
    
    
    
    Private Sub Form_Open()
         Call RecordForm("frmPrices")
    End Sub

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As I showed in my first reply, this will return the name of the form it's in:

    Me.Name
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    Hi everyone, and thanks for your combined inputs. I found another route for the same answer, so this thread now becomes redundant, as my solution didn't answer the question I asked originally (if that makes sense)

    I appreciate all your help, once again, thank you all

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

Similar Threads

  1. Replies: 2
    Last Post: 04-03-2014, 11:44 AM
  2. Replies: 3
    Last Post: 01-15-2014, 10:39 PM
  3. Replies: 5
    Last Post: 10-11-2013, 07:29 AM
  4. Open Form with instance method & wait to close?
    By GeorgeBakoyannis in forum Forms
    Replies: 1
    Last Post: 10-09-2010, 11:00 AM
  5. Multiple Instance Form
    By steve.roic@bellsouth.net in forum Forms
    Replies: 0
    Last Post: 05-19-2010, 11:18 AM

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