Results 1 to 3 of 3
  1. #1
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48

    Compile error "Sub or function not defined" problem with a public sub

    I have an application with two forms, let's call them frm1 and frm2. Initially only frm1 is open, and the sub that is run when a particular command button is clicked has code that ends with:

    DoCmd.OpenForm "frm2"
    Call ReviewConditions

    In the module for frm2, I've created the ReviewConditions sub as public, i.e.



    Public Sub ReviewConditions ()

    However I'm getting a compilation error "Sub or function not defined" on the "Call ReviewConditions" statement. I don't understand why this happens if the called sub ​is defined as public.

    Could it be because frm2 is being opened dynamically in the code for frm1? That's all I can think of, but I wouldn't have thought it was a compilation issue.

    Any suggestions would be welcome!

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Don't put the sub in the form, put it in a module.
    if it has to be in the form to do form things, then you have to call it thru the form,
    forms!myform1.reviewconditions

  3. #3
    BruceUK is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    48
    Quote Originally Posted by ranman256 View Post
    Don't put the sub in the form, put it in a module.
    if it has to be in the form to do form things, then you have to call it thru the form,
    forms!myform1.reviewconditions
    Thanks very much - your second option worked fine.

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

Similar Threads

  1. Compile error "variable not defined"
    By CHEECO in forum Access
    Replies: 11
    Last Post: 03-30-2016, 05:39 PM
  2. Replies: 1
    Last Post: 03-14-2013, 12:39 PM
  3. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  4. Replies: 1
    Last Post: 02-22-2011, 06:10 AM
  5. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 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