Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

Set Report control to date from opening form

I have a form that the user can enter a date and I want this data to appear on the report, but the text control keeps coming up blank.
Private Sub lblCreateReport_Click()
'Weekly project update report primiarily used by management to
'track what is going on
Dim strUserID   As String
Dim dteStartDate    As Date
Dim strType As String
'Need to check is user is a manager as they are the only ones allowed to run report

strUserID = VBUserName()
strType = DLookup("Type", "tblBOTHTeamMEmbers", "UserID = '" & strUserID & "' ")
dteStartDate = Me.txtStartDate

If strType = "MGR" Then
    Call CreateProjectQuery("Yes")
    DoCmd.OpenReport "rptProjects_Updates", acPreview
    Reports!rptProjects_Updates.txtStartDate = dteStartDate
    DoCmd.Close acForm, Me.name
Else
    MsgBox "You do not have permissions to run this report", vbOKOnly, "PERMISSION DENIED"
End If

End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

remove this declaration

Dim dteStartDate    As Date

from the click event and place in a regular module like this

Public dteStartDate    As Date


in the Reports Format event or Print event of the section where the textbox  "txtStartDate" is

place

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Reports!rptProjects_Updates.txtStartDate = dteStartDate
End Sub



Try this:
     
   Call CreateProjectQuery("Yes")
    DoCmd.OpenReport "rptProjects_Updates", acPreview,,,,dteStartDate ' OpenArgs
    DoCmd.Close acForm, Me.name


In the Report Open Event

Private Sub Report_Open (Cancel As Integer)
    Me.txtStartDate = Me.OpenArgs
End Sub
Avatar of Sandra Smith

ASKER

MX, I was trying that route but I keep getting the below error. User generated image User generated image
Sorry, I embeded the image twice.
I get this mesage on the Report in the open event.
Do I need the pound sign around the date?
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Simplest and worked, thank you both.

Sandra