Sandra Smith
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
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
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
ASKER
Sorry, I embeded the image twice.
ASKER
I get this mesage on the Report in the open event.
ASKER
Do I need the pound sign around the date?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Simplest and worked, thank you both.
Sandra
Sandra
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_Update
End Sub