Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Super Duper Nooby Question

Status
Not open for further replies.

mrdod

Technical User
Jun 12, 2006
103
US
I have never made a report in Access but am wishing to do so using an SQL statement. I understand how to set values from a report =[Forms]![frmreport]![textboxwhatever] but I am not sure how to do it using an SQL statement. If soemone can just nudge me in the right direction that would be awesome. Below is my code so far but I'm not sure if it will be helpful.

Option Compare Database
Option Explicit
Private Sub cmdreport_Click()

Dim strSQL As String
Dim dtmstart As Date
Dim dtmend As Date

dtmstart = Format(Me.dtmstart.Value, "mm/dd/yyyy")
dtmend = Format(Me.dtmend.Value, "mm/dd/yyyy")

'This is the information I need in a report.
strSQL = "SELECT [Employee Name],SUM[Hours Paid] AS [Hours Paid],Sum[Regular],SUM[Vacation]AS [Vacation],SUM[Regular]AS [Regular],SUM[Floating Holiday] AS [Floaters]" _
& " SUM[Sick] AS [Sick] AS [Sick],SUM[VTO]AS [VTO],SUM[Other] AS [Other] " _
& "FROM tblemployeehistory WHERE([Date Worked] BETWEEN #" & dtmstart & "# AND #" & dtmend & "#);"

Me.tbstart.Value = dtmstart 'From Date
Me.tbend.Value = dtmend 'To Date (Ending)

'Opens report.
DoCmd.OpenReport "rpthistory", acViewPreview

End Sub
 
Well I'm not totally embarrased because I atleast got my report to work. Maybe not the way I wanted to do it but hey I'm a newb. I made a Query and used the actual Form names
WHERE [Date Worked BETWEEN [Forms]![frmreport]![tbstart] AND [Forms]![frmreport]![tbend]

to sort the data. I don't know if this is the easiest way but it works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top