Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39

    How to link field

    From frmProjects via command button I am opening an input form with:

    Private Sub Command40_Click()
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenForm "frmRemarksInput", acNormal
    End Sub

    I need to include in this code a record number link, I want to link [Reference Number] from frmProjects to [Reference Number] in frmRemarksInput. How do I make this link?



    P.S. do I need the If Me.Dirty thingy? Not sure what it does.
    Thanks, Joe

  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
    Is this what you're looking for?

    http://www.baldyweb.com/wherecondition.htm

    The Dirty code forces the record to save if it isn't already.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    Hi Paul, I looked at that link you provided and it looks like I should do it like this according to the link:

    Private Sub Command40_Click()
    DoCmd.OpenForm "frmRemarksInput", , , "Reference_Number = '" & Me.Reference_Number & "'"
    End Sub

    However it is not working, I am getting a syntax error, what am I doing wrong??

    Thanks, Joe
    Last edited by jmk909er; 10-23-2010 at 01:05 PM. Reason: Left something out

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    The field is text I take it? Due to the inadvisable space in the name, you'll need to bracket it, like:

    [Reference Number]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    Hey Paul, I did not know that that space could be a problem, I think that it has been causing issues in other places now that I know that. Can you tell me if I have this right because it is still not working and do I need to have under scores between Reference and Number?

    Private Sub Command40_Click()
    DoCmd.OpenForm "frmRemarksInput", , , "[Reference Number] = '" & Me.[Reference Number] & "'"
    End Sub

  6. #6
    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 needs to be exactly the same as in the table, either space or underscore. What is the data type of that field in the table? Is the record saved at this point?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    It is a text field. The form opens to make a comment and is not saved untill the form closes. it is saved in frmRemarks that is a subdata sheet of the original record so that all comments are kept. Do I have the brackets in the right place?

  8. #8
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    It was working before by using
    =[Forms]![frmProjects]![Reference Number]
    in the field default field but I need to do it via command button because I want to input by using 2 different forms, one for user and one that admin will use

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    If the record isn't saved yet, try putting that "Dirty" line back before the OpenForm line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    I tried it like this:

    Private Sub Command40_Click()
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenForm "frmRemarksInput", , , "[Reference Number] = '" & Me.[Reference Number] & "'"
    End Sub

    and it is still not populating anything??

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39

    DB File

    Ok, Here it is. Here is exactly what I am trying to fix: In the 2 forms "frmProjects" and "frmProjectsViewer" there is a command button "Make New Comment" I want it to open "frmRemarks" with the "Reference Number" populated from the respective first form. on load it already populates the date and user name. Please let me know if you need more info.

    Non of the data is sensitive or private (Just test data)

    Thanks, Joe

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    I assume you mean frmRemarksInput. The data entry property of that form is set to yes, so it will always open to a new record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    Yes it is frmRemarksInput and yes it is suppose to always open to make a new comment

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Ah; I'd do it this way instead then:

    DoCmd.OpenForm "frmRemarksInput"
    Forms!frmRemarksInput.[Reference Number] = Me.Reference_Number
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Link Master Field and Link Child Field
    By evander in forum Forms
    Replies: 2
    Last Post: 05-25-2010, 09:13 PM
  2. Link Master Field Error
    By Lynn in forum Access
    Replies: 6
    Last Post: 04-11-2010, 01:00 PM
  3. Replies: 7
    Last Post: 02-08-2010, 12:14 PM
  4. Link ComboBox to field in a table
    By DrDebate in forum Forms
    Replies: 0
    Last Post: 04-27-2007, 08:03 AM
  5. Create the link
    By accessman2 in forum Access
    Replies: 0
    Last Post: 03-13-2006, 01:16 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
  •  
Other Forums: Microsoft Office Forums