Results 1 to 6 of 6

Thread: [RESOLVED] Access: Sub or Function not defined

  1. #1
    Member
    Join Date
    Apr 05
    Location
    Arlington, TX
    Posts
    60

    Resolved [RESOLVED] Access: Sub or Function not defined

    I have two separate forms (not subforms or anything. just two normal forms), one of which is linked to my data table, and the other one is a sort of welcome screen which allows the user to find records and create new records. Unfortunately, the creating of records isn't working as well as I'd like.

    The way I have it set up right now is the user types either the name they want to search for or the name they want to add, and clicks the appropriate button.

    Here's the welcome screen code:
    Code:
    Sub cmdNew_Click()
      txtName.SetFocus
      newEmployee = txtName.Text
      DoCmd.OpenForm "Page1"
      DoCmd.GoToRecord acDataForm, "Page1, acNewRec"
      populateNewRecord newEmployee
    End Sub
    and the data form code:
    Code:
    Public Sub populateNewRecord(newEmployee As String)
      txtEmployeeName.Text = newEmployee
    End Sub
    As you can see, in an effort to automatically populate the name, I'm saving the contents of the text box, and sending it off to a function in the data form. Unfortunately, it's telling me that it's not defined, and I have no idea how to fix it. :/

  2. #2
    Member
    Join Date
    Nov 03
    Location
    Cambs, UK
    Posts
    55

    Re: Access: Sub or Function not defined

    Just taken another look at the code. Try:

    vb Code:
    1. Sub cmdNew_Click()
    2.   txtName.SetFocus
    3.   newEmployee = txtName.Text
    4.   DoCmd.OpenForm "Page1"
    5.   DoCmd.GoToRecord acDataForm, "Page1", acNewRec
    6.   populateNewRecord(newEmployee)
    7. End Sub


    ~ James

  3. #3
    Member
    Join Date
    Apr 05
    Location
    Arlington, TX
    Posts
    60

    Re: Access: Sub or Function not defined

    No change.

  4. #4
    Member
    Join Date
    Nov 03
    Location
    Cambs, UK
    Posts
    55

    Re: Access: Sub or Function not defined

    OK, I've just duplicated what you have here:

    Move:

    vb Code:
    1. Public Sub populateNewRecord(newEmployee As String)
    2.   txtEmployeeName.Text = newEmployee
    3. End Sub

    to a new module. Save it, watch it run (I hope).


    (Make sure you make those other changes I've suggested above, otherwise they will cause problems too).

  5. #5
    Member
    Join Date
    Apr 05
    Location
    Arlington, TX
    Posts
    60

    Re: Access: Sub or Function not defined

    Thanks! It's working great now.

    (Although I can't believe I had the quotes in my GoToRecord line so messed up...)

  6. #6
    Member
    Join Date
    Nov 03
    Location
    Cambs, UK
    Posts
    55

    Re: [RESOLVED] Access: Sub or Function not defined

    Hehe no worries!

Posting Permissions

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