Results 1 to 7 of 7
  1. #1
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85

    Button on the form

    Ok, here is my issue guys :

    I have a Customer form with CustomerID and CustomerName textbox on it, then i have a Building_SubFrom displayed as Datasheet underneath those text boxes. I have create View Building Info Button in the header of the Customer from, which opens up Building_Information Form. However, the issue that i cant figure out is how to make the button outside Building_Subform to populate Building_Information Form based on its information. I have no trouble doing it differently, but i really want to follow this design format.

    I have tried this code, which works fine for just opening the form:

    Private Sub cmd_ViewBuildingInfo_Click()

    Me.Building__Subform.SetFocus

    DoCmd.OpenForm "Building_Information"


    End Sub

    However, the code (which i though would be appropriate) gives me an error:

    Private Sub cmd_ViewBuildingInfo_Click()

    Me.Building__Subform.SetFocus

    DoCmd.OpenForm "Building_Information", , , "BuildingID = & " & Me.BuidingID


    End Sub

    I know the problem is that Vba cant find contol Me.BuildingID, which is the part of Buidling_Subform, so i though SetFocus on this form would solve the problem, however it does not.

    Please suggest

    Regards



    Evgeny

  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,530
    It would make more sense to have the button in the detail section of the subform. That way, you know which building the user wants to see (I'm assuming it displays more than one). The alternative if you want to stay with what you've got is:

    DoCmd.OpenForm "Building_Information", , , "BuildingID = " & Me.Building__Subform.Form.BuidingID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    Yeah it would but i display subform as Datasheet . I tried this code

    DoCmd.OpenForm "Building_Information", , , "BuildingID = " & Me.Building__Subform.Form.BuidingID,

    but it only returns the values of the first record, when i select next record it shows nothing

  4. #4
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    Oh god, something is really weird with my Access, i tried your solution like 4 times, and 5th time it worked heheh. Thank you. Would my design be considered as bad practice or i can just go ahead with it?

  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,530
    Like I said, I would lean towards code in the subform, either a button or in the double-click event of a textbox. A button won't show in datasheet view but it would in continuous forms view. With a button on the main form, it's going to pull either the first record or the last record with focus, but in my mind that's less reliable than code in the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    Thank you for suggestion. It works fine without Focus and brings up information about any record i choose, i will look into continuous form view, but its' design control frustrates me a lot hah. Thank you

  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,530
    Glad it's working for you. I guess it's a matter of preference. I feel I have a lot more control with continuous form view.
    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. run button on parent form
    By Mclaren in forum Programming
    Replies: 4
    Last Post: 04-28-2010, 01:20 AM
  2. form button
    By mmp in forum Programming
    Replies: 1
    Last Post: 03-04-2010, 10:55 AM
  3. Replies: 1
    Last Post: 03-03-2010, 07:29 PM
  4. How to Fix the button postion in the form
    By Progress2007 in forum Forms
    Replies: 1
    Last Post: 09-16-2009, 12:24 PM
  5. email button in form
    By peterinbristol in forum Forms
    Replies: 0
    Last Post: 03-19-2007, 02:25 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