Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Form to open to specific record (DB attached) Question


    Views: 6 Size: 97.3 KB">Database4.zip



    HI all,
    I am trying to get this Edit button on primary form (Sample DB) to open another form, to specific records in the forms sub forms.
    I have done this with a different db but cant seem to get it to work with this one?
    I have tried the following code and neither one works correctly. It opens forms but not to specific records.

    DB Opens to Primary Form
    If you open it, you will see what I mean


    Code:
    Private Sub cmdEdit_Click()
        If Me.cboAccountTypeID = 0 Then
        
            MsgBox "You must select a Record to edit!"
      Else
        DoCmd.OpenForm "frmSystemCategoryData", , , "Forms!frmSystemCategoryData!sfrmSystemCategoryType.Form!SystemCategoryTypeID = Me.cboAccountTypeID.Column(1)" _
        & "Forms!frmSystemCategoryData!sfrmSystemCategory.Form![SystemCategoryID] = Me.cboAccountNameID.Column(1)"
        Forms!frmSystemCategoryData!sfrmSystemCategorySub.SetFocus
        DoCmd.GoToRecord , , acNewRec
    
    
      End If
    End Sub
    
    
    Private Sub CmdEdit_Click()
        If Me.cboAccountTypeID.Column(0) & "" = "" Then
        
            MsgBox "MsgBox "You must select a Record to edit!"
      Else
        DoCmd.OpenForm "frmSystemCategoryData"
        Forms!frmSystemCategoryData!sfrmSystemCategoryType.SetFocus
        DoCmd.FindRecord Me.cboAccountTypeID.Column(1)
        Forms!frmSystemCategoryData!sfrmSystemCategory.SetFocus
        DoCmd.FindRecord Me.cboAccountNameID.Column(1)
        Forms!frmSystemCategoryData!sfrmSystemCategorySub.SetFocus
        DoCmd.GoToRecord , , acNewRec
    
    
      End If
    End Sub
    Can someone assist me with this?
    Thanks
    Dave

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,945
    On my tablet, so dB no good ATM.
    I would either use the where clause of the open form, or pass in the key as openargs and then findfirst.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    If you don't concatenate references or variables but put them within all the quotes instead, your are not passing the reference value, you are passing a literal string.
    So you are not saying WHERE somthing equals what's IN Me.cboAccountTypeID.Column(1) you are passing literally WHERE something = "Me.cboAccountTypeID.Column(1)"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Can't use WHERE argument of OpenForm to filter a subform. OpenForm can only refer to main form, not subforms. So this would never work anywhere even if syntax were correct.

    A reference that uses full path, not Me alias, can be embedded between quotes. "something = Forms!frmSystemCategoryData.cboAccountNameID". I have always concatenated with Me.

    Two of the subforms have a filtered RecordSource: SELECT * FROM tblSystemCategorySub WHERE [SystemCategoryID]=1;
    Then you try to filter that with VBA FindRecord for SystemCategoryTypeID. None of the records have the SystemCategoryTypeID of 5. The combobox is set to show only this one SystemCategoryTypeID.

    Also, seems code behind subforms may be conflicting with the frmCOA code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I didn't mean it that way. I meant the filtering was where something equals something, not to use a sql where clause. It was meant to be the WHERECONDTION of the OpenForm method. I guess I shouldn't have capitalized it? Also, this says otherwise re concatenation, so that's what I've always done

    https://learn.microsoft.com/en-us/of...docmd.openform

    See last example
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Yes, I know it was meant to be WHERE CONDITION argument of OpenForm. WHERE CONDITION follows SQL WHERE clause requirements. This works:

    DoCmd.OpenForm "sfrmSystemCategory", , , "SystemCategoryID=Forms!frmCOA.cboAccountTypeI D"

    However, including .Column(1) fails, as it would in a query object.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    .Column(1) fails, as it would in a query object.
    It works in a query if you use Eval()
    Last edited by Micron; 04-08-2024 at 06:33 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Tried. Just throws Undefined Function error.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Saw it posted somewhere; perhaps by Albert D. Kallal. Would have to look to see if I saved my test query, or you could Google how to use .Column property in a query field because that's how I found it.
    PM to remind me if I forget to follow up and you want to see the sql. No guarantee that I saved it.

    EDIT - BTW, it was a listbox or combo box column if that matters.
    EDIT2, as you've probably noted before, best to post what you tried. IIRC your expression has to be quoted inside the Eval. Did you do that?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Couldn't find; had to re-create. This works (these are not my field/object names)
    Code:
    SELECT [Attendance Log].EmployeeID, [Attendance Log].[Last Name], [Attendance Log].[First Name]
    FROM [Attendance Log]
    WHERE ((([Attendance Log].[First Name])=Eval("Forms![Attendance Log1].Combo20.Column(2)")));
    Hopefully it applies to what you were saying re: not being able to use .Column property in a query. I imagine it could work for a where condition as well, but I've never tried.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Ok, works. Wasn't using quote marks. Doh!
    Works with OpenForm also: "[First Name]=Eval('Forms![Attendance Log1].Combo20.Column(2)'")

    Works with listbox as well.


    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi June7
    I have tried the following two, both open form but do not go to the record that matches my combo? I am sure it has something to do with my code but not sure?

    Code:
    DoCmd.OpenForm "frmSystemCategoryData", , , ("SELECT [tblSystemCategoryType].[SystemCategoryTypeID]
     FROM [tblSystemCategoryType] 
    WHERE ((([tblSystemCategoryType].[SystemCategoryTypeID])=Eval('Forms![tblCOA].[cboAccountTypeID.Column(1)')))")
    
    DoCmd.OpenForm "frmSystemCategoryData" ,,,"[tblSystemCategoryType].[SystemCategoryTypeID])=Eval('Forms![tblCOA].[cboAccountTypeID.Column(1)'")
    Both Compile but only open form to first record on the first sub form
    Thanks
    Dave

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Yes, the single or double quotes are required because Eval returns a string.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    ID fields are usually column 0. Are you sure you're using the correct column (because the columns collection is zero based)?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron
    I beleive I am,
    Here is row source

    Code:
    SELECT [SystemCategoryID], [SystemCategoryTypeID], [SystemCategoryName] FROM tblSystemCategory WHERE [SystemCategoryTypeID]=5 ORDER BY [SystemCategoryName];

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

Similar Threads

  1. Replies: 3
    Last Post: 01-30-2022, 01:34 AM
  2. Open form with specific record
    By Lukael in forum Programming
    Replies: 14
    Last Post: 11-16-2015, 06:31 AM
  3. 'SubTable' to manage items attached to a specific record
    By RichardGR in forum Database Design
    Replies: 4
    Last Post: 04-03-2013, 02:37 AM
  4. Open form on specific record
    By iky123 in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 09:56 AM
  5. Open form to specific record
    By Two Gun in forum Forms
    Replies: 7
    Last Post: 11-09-2011, 10:00 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