Results 1 to 13 of 13
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Issue with a linked fields from a Form to Report

    Hi everyone,



    I'm creating a report named [Report_Graph_rpt] that it has into two unbound fields named [rStartdatetxt] and [rEnddatetxt]
    I am filling info into a form named [Graph_frm] with the fields named [fStartdatetxt] and [fEndDatetxt], when I click on a button I want to open the report [Report_Graph_rpt] and the unbound fields take the values from the form

    I have this code, but when the report opens, it shows the textboxes on the report empty, I don't know why... any idea?


    Private Sub Reportcmd_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim SystemDateRun As String

    stDocName = "Report_Graph_rpt"
    SystemDateRun = "01/01/2010"

    If IsNull(fStartDatetxt) Or Me.fStartDatetxt = "" Or IsNull(fEndDatetxt) Or Me.fEndDatetxt = "" Then

    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria, acNormal

    [Reports]![Report_Graph_rpt]!rStartdatetxt = SystemDateRun
    [Reports]![Report_Graph_rpt]!rEnddatetxt = Date

    Else

    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria, acNormal

    Reports![Report_Graph_rpt]!rStartdatetxt = Me.fStartDatetxt
    Reports![Report_Graph_rpt]!rEnddatetxt = Me.fEndDatetxt

    End If

    MsgBox "Report of graphs", vbInformation, "Testing"

    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Cannot set value of textbox on report like that. An expression in textbox ControlSource can reference form textbox. Expression can use IIf() function or can call a custom user function.
    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.

  3. #3
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi!
    How do you recommend to set the expression into he controlsource for the textbox in the report? I appreciate your help!!

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Quote Originally Posted by charly.csh View Post
    Hi!
    How do you recommend to set the expression into he controlsource for the textbox in the report? I appreciate your help!!
    You could use Tempvars if you want to use control source, or just set by passing in as OpenArgs?, or even refer to the whole form name Forms!FormName!ControlName

    The latter I have never done as it ties that report control to just that form.
    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

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Leave just the Docmd.OpenReport line in the click event of the button on the form and move the code to the open event of the report:
    Code:
    Private Sub Report_Open(Cancel As Integer)
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim SystemDateRun As String
    
    stDocName = "Report_Graph_rpt"
    SystemDateRun = "01/01/2010"
    
    If Nz(Forms!Graph_frm!fStartDatetxt)  = "" Then 
        Me.rStartdatetxt = SystemDateRun
    Else
        Me.rStartdatetxt=Forms!Graph_frm!fStartDatetxt
    End If
    
    If Nz(Forms!Graph_frm!fEndDatetxt) ="" Then
        Me.rEnddatetxt = Date
    Else
        Me.rEnddatetxt = Forms!Graph_frm!fEndDatetxt
    End If
    
    
    MsgBox "Report of graphs", vbInformation, "Testing"
    
    
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi

    I followed the sugested idea but it still shows an error to assign a value the bounded textboxes on the report

    I have this on the Form

    Private Sub Reportcmd_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Graph_Rpt"

    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria, acNormal
    MsgBox "Graph", vbInformation, "Testing"

    End Sub



    I have this on the report

    Private Sub Report_Open(Cancel As Integer)
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim SystemDateRun As String

    stDocName = "Report_Graph_Rpt"
    SystemDateRun = "01/01/2010"
    If Nz([Forms]![Graph_Frm]![fStartDatetxt]) = "" Then
    Me.rStartDatetxt = SystemDateRun
    Else
    Me.rStartDatetxt = [Forms]![Qsys_GrafAccDep_Frm]![fStartDatetxt]
    End If
    If Nz([Forms]![ Graph_Frm]![fEndDatetxt]) = "" Then
    Me.rEnddatetxt = Date
    Else
    Me.rEnddatetxt = [Forms]![Graph_Frm]![fEndDatetxt]
    End If

    End Sub

    The error shown without info is here

    Me.rStartDatetxt = SystemDateRun '(SystemDateRun) it takes the value but Me.rStartDatetxt doesn't

    I appreciate the help!!

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Please review the updated code below (use the code tags -#- in the forum to post code to preserve indentation):
    Code:
    Private Sub Reportcmd_Click()
    
    
    Dim stDocName As String
    'Dim stLinkCriteria As String
    stDocName = "Graph_Rpt"
    
    
    DoCmd.OpenReport stDocName, acViewPreview ', , stLinkCriteria, acNormal 
    MsgBox "Graph", vbInformation, "Testing"
    
    
    End Sub
    
    
    Private Sub Report_Open(Cancel As Integer)
    'Dim stDocName As String
    'Dim stLinkCriteria As String
    Dim SystemDateRun As Date 'String
    
    
    'stDocName = "Report_Graph_Rpt"
    SystemDateRun = #01/01/2010# 'if it is a date you need to declare it as date and wrap it in #; if left as string you need to use the CDate() function when you assign it to the textbox
    
    
    If Nz([Forms]![Graph_Frm]![fStartDatetxt]) = "" Then
    	Me.rStartDatetxt = SystemDateRun 'if left as string her you should have CDate(SystemDatetxt)
    Else
    	Me.rStartDatetxt = [Forms]![Qsys_GrafAccDep_Frm]![fStartDatetxt]
    End If
    
    
    If Nz([Forms]![ Graph_Frm]![fEndDatetxt]) = "" Then
    	Me.rEnddatetxt = Date
    Else
    	Me.rEnddatetxt = [Forms]![Graph_Frm]![fEndDatetxt]
    End If
    
    
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Linkfromformtoreport (2).zipLinkfromformtoreport (2).zipHi
    still with some issues,
    I changed the code and used the suggested one but still with issues

    I added here the example just with the part I need, I appreciate if you can look at this

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I don't think code can directly set Value property of textboxes on report. Pull value into textbox with ControlSource expression referencing form control, TempVar, OpenArgs, or a custom function.
    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.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Quote Originally Posted by June7 View Post
    I don't think code can directly set Value property of textboxes on report. Pull value into textbox with ControlSource expression referencing form control, TempVar, OpenArgs, or a custom function.
    I did that recently for another poster, but in the Load event?

    Code:
    Private Sub Report_Load()
    Me.txtRptName = Me.Name
    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

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Here it is without code in the report.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Ok, am corrected, use report's Load event.
    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.

  13. #13
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hey thank you for the solution!! was great and it works perfectly!!!!

    Also thanks to all of you guys! good advises for learning more!!!

    Something as well that also work I replaced the textboxes por labels and used the property .caption and it works too, I don't know why it didn't work with textboxes

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

Similar Threads

  1. Replies: 2
    Last Post: 09-20-2021, 09:57 AM
  2. Generate report with blank linked table fields
    By e-support in forum Reports
    Replies: 14
    Last Post: 01-06-2017, 04:11 PM
  3. Open Report linked to Query Issue
    By McArthurGDM in forum Reports
    Replies: 6
    Last Post: 07-22-2014, 12:13 PM
  4. Issue with seach fields in form
    By Cheryl_Granieri in forum Forms
    Replies: 1
    Last Post: 03-24-2013, 10:50 AM
  5. Form Issue (repetitive fields)
    By netchie in forum Access
    Replies: 2
    Last Post: 08-15-2011, 02:39 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