Results 1 to 12 of 12
  1. #1
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156

    Compile error "variable not defined"

    I have a form in my data base with the below code. I am getting an Compile error "variable not defined" on line Forms!Homepage.Search Liberi = Me.[Person ID]. I am not sure why.



    Code:
    Option Compare Database
    Option Explicit
    Private Sub AddChildsRecord_Click()
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.OpenForm "Homepage"
        Forms!Homepage.Search Liberi = Me.[Person ID]
        DoCmd.OpenForm "ChildRecord"
        DoCmd.Close acForm, "AddChild"
        DoCmd.Close acForm, "Homepage"
    End Sub
    Thank-you Cheeco

  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
    If "Search Liberi" is the name of a control with an inadvisable space, it would need to be bracketed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    I have made the below changes and I still get the error on the same line

    Code:
    Option Compare Database
    Option Explicit
    Private Sub AddChildsRecord_Click()
    Dim ThisForm As String
    ThisForm = Me.Name
    Dim strfield As String
    Dim strotherfield As String
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.OpenForm "Homepage"
    Forms!Homepage.[SearchLiberi ID] = Me.[person ID]
    DoCmd.OpenForm "Child Record"
    DoCmd.Close acForm, "Add Child"
    DoCmd.Close acForm, "Homepage"
    End Sub

  4. #4
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    I have noticed I am getting this same error for both the below private subs Forms!Homepage.[Search Liberi ID] = Me.[Person ID] and Forms!Homepage.Search [Assessor] = Me.[Assessor Name]. It must be something simple that I just don't understand. Help me out here.

    [CODEOption Compare Database
    Option Explicit

    Private Sub AddChildsRecord_Click()
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.OpenForm "Homepage"
    Forms!Homepage.[Search Liberi ID] = Me.[Person ID]
    DoCmd.OpenForm "Child Record"
    DoCmd.Close acForm, "Add Child"
    DoCmd.Close acForm, "Homepage"
    End Sub

    Private Sub EditChildDetails_Click()
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.OpenForm "Homepage"
    Forms!Homepage.Search [Assessor] = Me.[Assessor Name]
    DoCmd.OpenForm "Assessor Records Form"
    DoCmd.Close acForm, "Add Assessor"
    DoCmd.Close acForm, "Homepage"
    End Sub


    ][/CODE]

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What are the names of your forms and controls? The second has the same problem of an un-bracketed space.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    Quote Originally Posted by pbaldy View Post
    What are the names of your forms and controls? The second has the same problem of an un-bracketed space.
    The main form is "Homepage" There are two buttons that take you to Form "Addchild" and Form "Addasssessor" You then fill out the info and click the add button. That is when the error pops up when you click the add button.
    I did make the a change to the line Forms!Homepage.[Search Assessor] = Me.[Assessor Name]. I put the search word in the brackets with the word Assessor. That did not help. I am not sure what you mean by "The second has the same problem of an un-bracketed space".

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I don't have A2016 but -

    Are you sure .Search is a form method? I don't think it is, because I can find no reference to it anywhere, and it is not in the list here:

    https://msdn.microsoft.com/en-us/lib.../jj249491.aspx

    It would not be the first time Access gives a completely misleading error message, but it sure would explain why you get an error.

  8. #8
    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'm not sure what you mean by "I put the search word in the brackets with the word Assessor". The code you're using is expecting names of controls (textbox, combo, etc). What are you trying to accomplish?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    When you click add child or add assessor it is to add the info to the proper table. It does do that, it adds the info to the table but it gives that error every time.

    If you look at the second private sub code. In this line Forms!Homepage.Search [Assessor] = Me.[Assessor Name] the word search is not in the square brackets with the word Assessor like the first private sub code. So I changed it to Forms!Homepage.[Search Assessor] = Me.[Assessor Name]. In the first private sub code the word search is in the square brackets with the word Liberi ID. Forms!Homepage.[Search Liberi ID] = Me.[Person ID]. So in the end I need it to update the data to the proper table without giving that error. I have attached a copy of the database.
    Attached Files Attached Files

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, in the sample, the two textboxes are named:

    SearchLiberiID
    SearchAssessorName

    so those are what you'd need to use. For example, this line works:

    Forms!Homepage.SearchAssessorName = Me.[Assessor Name]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    Thank-you pbaldy. Great Job. With correction I was able to make the correct changes to the add child form as well.

    Thanks again

    Cheeco
    Last edited by CHEECO; 03-30-2016 at 05:30 PM. Reason: resolved

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 03-14-2013, 12:39 PM
  2. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  3. Compile error: Variable not defined
    By HarryScofs in forum Access
    Replies: 8
    Last Post: 07-25-2011, 09:06 AM
  4. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 PM
  5. Replies: 23
    Last Post: 03-26-2009, 06:50 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