Results 1 to 4 of 4

Procedure Call on Separate Form

  1. #1
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    206

    Procedure Call on Separate Form

    What is the correct way to Call a procedure on a form from another form or module?



    The concept:

    Someone does something on one form and that form references a module. Once the module is referenced/evaluated it references to a specific point in the form that called the module in the first place.

    For Example:

    1. Uer enters data and clicks a button.
    2. Form calls theModuleProcedure. (Call theModuleProcedure)
    3. theModuleProcedure evaluates the user data entered.
    4. Module calls a certain point in the original form. (Call frmL.btnLogin_Click_Exit)


    The following is the error message I receive when trying to Call frmL.btnLogin_Click_Exit:
    Click image for larger version. 

Name:	Capture.JPG 
Views:	11 
Size:	19.3 KB 
ID:	39454

    Note: frmL is defined as Dim frmL As Form_frmLogin in the module.

    When I change to Call frmL.btnLogin_Click.btnLogin_Click_Exit the following error appears with .btnLogin_Click highlighted:
    Click image for larger version. 

Name:	Capture.JPG 
Views:	11 
Size:	17.6 KB 
ID:	39455

    When I change to Call frmL.btnLogin_Click the following error message appears:
    Click image for larger version. 

Name:	Capture.JPG 
Views:	11 
Size:	14.3 KB 
ID:	39456

    frmL = Form_frmLogin
    Form Procedure = btnLogin_Click
    Login_Click Procedure = btnLogin_Click_Exit (this prevents a loop from occurring if issue detected)

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,029
    Note: frmL is defined as Dim frmL As Form_frmLogin i
    Dim frmL As Form as a start (in some cases, such objects need to be Dim'd as Object). Then SET the object variable as in SET frmL = NameOfSomeForm
    Plus, to call a built in event such as Exit or Click the default Private needs to be changed to Public. However, the line is confusing to me
    frmL.btnLogin_Click.btnLogin_Click_Exit
    Surely that is not a built in event.
    AFAIK, you cannot assign the name of an object within the Dim statement as you are doing.
    P.S. is is rarely a good idea to run form module events from other forms or procedures.
    Last edited by Micron; 08-16-2019 at 02:36 PM.
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.
    Sometimes I talk to myself - like when I need expert advice.

  3. #3
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    206
    I tried every variable I could think of and the same issue continued.

    The point is I was trying to access a specific point in a form after the module the evaluation it was programmed to do.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,317
    As Micron explained this isn't a great idea on a number of levels.

    Firstly you would have to guarantee that the module called always had to close the form it called, this would surely drastically reduce the usefulness of a reusable code module?
    Is the module a function returning a result ?

    Also as mentioned you have to change code in the form to Public to enable it to be called from anywhere other than the originating form.

    The syntax should you really want to do it would be

    Code:
     Forms("YourFormName").cmdFind_Click
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Invalid procedure call
    By cebrower in forum Queries
    Replies: 7
    Last Post: 09-26-2018, 06:07 AM
  2. Invalid procedure call
    By RonL in forum Queries
    Replies: 0
    Last Post: 05-16-2016, 02:19 PM
  3. Invalid Procedure Call
    By neo651 in forum Queries
    Replies: 21
    Last Post: 09-11-2011, 12:58 PM
  4. Replies: 6
    Last Post: 04-24-2010, 11:12 AM
  5. how to call a sub procedure?
    By dollygg in forum Access
    Replies: 1
    Last Post: 08-18-2009, 05:10 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
  •  
Tech Forums: Microsoft Office Forums