Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2022
    Posts
    17

    Help with VBA Code, from Report to Form to Sub Form

    Hello and thanks for taking a look. Frank


    On a Report I have an OnClick event on the “Description” control that opens “Add Clients” form that matches the CustomerID of the Report to the Form (Add Clients). This works!
    Second, Closes the Report. This also works!
    Third, Goes to the control “CustomerContactF” This is a continuous sub form on the Add Clients form. This works.
    Fourth, Goes to the control “Description” which is a field inside the “CustomerContactF”, this is placing the cursor at the beginning of the Subform (they are in date order). I am looking to have the cursor placed on the ‘Description” row of the click from the above Report
    The DoCmd.FindRecord seems to be ignored. No error messages, but open on the “Description” line at the beginning.

    Private Sub Description_Click()
    DoCmd.OpenForm "Add Clients", , , "CustomerID=" & CustomerID
    DoCmd.Close acReport, "CLIENTS FOLLOW-UP CONTACT"
    DoCmd.GoToControl "CustomerContactF"
    DoCmd.GoToControl "Description"
    DoCmd.FindRecord "Description"
    End Sub

    Click image for larger version. 

Name:	Images of Report and Form.png 
Views:	16 
Size:	119.5 KB 
ID:	51345

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Reports are typically meant for reading or printing. Forms are used for interaction with the user.
    Why are you using Report for interaction?

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    How are you meant to find something with Description in it?
    I would expect at least "Description = " & <YourDescription Value>
    https://learn.microsoft.com/en-us/of...cmd.findrecord Even then you need to search for the value, not the name of the control?

    I would use FindFirst.

    I just tested it on a subform in my form on a command button on the mainform, so pay attention to the syntax. Do NOT just copy as it is.

    Code:
    Private Sub cmdDaily_Click()
        TempVars("WeekNum").Value = DatePart("ww", Me.cboDates.Column(1))
        DoCmd.OpenForm "frmDailyList", acFormDS, , , , acDialog
        Me.sfcsfrmDaily.Form.Recordset.FindFirst "DailyID = 2037"
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Join Date
    Sep 2022
    Posts
    17
    Hi,
    True about reports, but I always open in Print preview. I find it easier to just click an item on the report to go where I need to go on a particular form.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    To each their own.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Try this please:
    Code:
    '.........
    DoCmd.FindRecord Me.Description ' your original code was looking for the word "description" not the value of the Description textbox on the report
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 15
    Last Post: 03-13-2022, 04:28 PM
  2. Code to email Report from Form
    By swenger in forum Programming
    Replies: 1
    Last Post: 02-06-2019, 12:12 PM
  3. How to modify code to open report instead of form
    By kassem in forum Programming
    Replies: 4
    Last Post: 06-10-2014, 07:02 PM
  4. Replies: 7
    Last Post: 12-12-2012, 03:14 PM
  5. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 02:18 AM

Tags for this Thread

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