i 仅从一个表格中得出一个非常简单的报告。 表中的一个栏目是日期。
i 有必要使报告用户能够进入一系列日期,并在日期之间显示数据。
如何这样做?
i 仅从一个表格中得出一个非常简单的报告。 表中的一个栏目是日期。
i 有必要使报告用户能够进入一系列日期,并在日期之间显示数据。
如何这样做?
最好的解决办法可能是建立一个小的形式,使用户能够进入日期。 报告所依据的问题是:
SELECT f1,f2,f3 FROM Table
WHERE SomeDate
BETWEEN Forms!DateSelect!StartDate AND Forms!DateSelect!EndDate
我不喜欢在表格/报告记录中打字参数或编号,因此,我会修改“Remou”的想法,而是在报告《奥本报》中确定记录。 这是首先开放的形式,收集了选定日期的数值,然后将这些数值推入报告记录内容。 与此类似(从地雷的真实报告中加以阐述):
Dim strRecordSource As String
DoCmd.OpenForm "dlgDateRange", , , , , acDialog, "ThisYear"
If IsLoaded("dlgDateRange") Then
With Forms!dlgDateRange
If .Tag = "Cancel" Then
Cancel = True
Else
Me.Filter = "[InvoiceDate] Between #" & !txtStart & "# AND #" & !txtEnd & "#"
Me.FilterOn = True
Me!lblDateRange.Caption = StrConv(Trim(("from " + varZLStoNull(Format(!txtStart, "mm/dd/yyyy"))) & (" to " + varZLStoNull(Format(!txtEnd, "mm/dd/yyyy")))), vbProperCase)
End If
End With
DoCmd.Close acForm, "dlgDateRange"
End If
一些评论:
(source: dfenton.com)
I use Stephan Lebansday 取码,允许用户从日历控制中抽出一个日期。
规定日期范围的准则是这样,我必须这样做的是通过这一标准。
Public Sub SetDates(strType As String, ctlStart As Control, ctlEnd As Control)
Dim dteStart As Date
Dim dteEnd As Date
Dim ctl As Control
Select Case strType
Case "EndOnly" OK
dteStart = #1/1/1980#
ctlStart.Enabled = False
dteEnd = Date
Case "Trace" OK
dteStart = DateAdd("d", -7, Date)
dteEnd = DateAdd("d", 7, Date)
Case "LastWeek" OK
dteStart = Date - Weekday(Date, vbMonday) - 6
dteEnd = dteStart + 6
Case "ThisWeek" OK
dteStart = Date - Weekday(Date, vbMonday) + 1
dteEnd = dteStart + 6
Case "LastMonth" OK
dteStart = month(DateAdd("m", -1, Date)) & "/01/" & year(DateAdd("m", -1, Date))
dteEnd = DateAdd("m", 1, dteStart) - 1
Case "ThisMonth" OK
dteStart = month(Date) & "/01/" & year(Date)
dteEnd = DateAdd("m", 1, dteStart) - 1
Case "LastQuarter" OK
dteStart = DateSerial(year(DateAdd("q", -1, Date)), (3 * Format(DateAdd("q", -1, Date), "q")) - 2, 1)
dteEnd = DateAdd("q", 1, dteStart) - 1
Case "ThisQuarter" OK
dteStart = DateSerial(year(Date), (3 * Format(Date, "q")) - 2, 1)
dteEnd = DateAdd("q", 1, dteStart) - 1
Case "LastYear" OK
dteStart = "01/01/" & year(Date) - 1
dteEnd = "12/31/" & year(Date) - 1
Case "ThisYear" OK
dteStart = "01/01/" & year(Date)
dteEnd = "12/31/" & year(Date)
Case "LastFY" OK
dteStart = "09/01/" & year(DateAdd("m", 4, Date)) - 2
dteEnd = DateAdd("yyyy", 1, dteStart) - 1
Case "ThisFY" OK
dteStart = "09/01/" & year(DateAdd("m", 4, Date)) - 1
dteEnd = DateAdd("yyyy", 1, dteStart) - 1
Case "Last3Years" OK
dteStart = "01/01/" & year(Date) - 2
dteEnd = Date
Case "BeforeLast3Years" OK
dteEnd = DateValue("01/01/" & year(Date) - 2) - 1
Case Else
dteStart = Date
dteEnd = Date
End Select
If ctlStart.Enabled Then
If dteStart = 0 Then
ctlStart = Null
Else
ctlStart = Format(dteStart, "mm/dd/yyyy")
End If
End If
If ctlEnd.Enabled Then
If dteEnd = 0 Then
ctlEnd = Null
Else
ctlEnd = Format(dteEnd, "mm/dd/yyyy")
End If
End If
For Each ctl In ctlStart.Parent!optPresetDates.Controls
If ctl.ControlType <> acLabel Then
If Replace(ctl.Controls(0).Caption, " ", vbNullString) = strType Then
ctlStart.Parent!optPresetDates = ctl.OptionValue
Exit For
End If
End If
Next ctl
Set ctl = Nothing
End Sub
这确实比你需要更多的信息,但我想说的是,你应考虑把你的报告记录与参数或辩证表分开。
我将做的是提出一个问题,选择表格中的所有各行,就时间而言,第一编确定了两个参数。 如下:
在查询设计中注明日期:
格式([YourDate Field],“mmm. dd,yyyyyy”)
标准撰写:
格式([From],“mmm. yy, dddddd”) And Format([To],“mmm. dd. yyyyyyy”)
当你提出询问时,应有两个投入箱来申请<代码>。 从和到
,具体格式。
In C#, I know that I can overload the constructor for a class by specifying it in the body of the class: public class MyClass() { public MyClass(String s) { ... } } This overrides the default ...
I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...
I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...
The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...
I m using Application run to call several macros in order like this. Sub Run_All_Macros() Application.Run ("Macro_1") Application.Run ("Macro_1") End Sub When I start Run_All_Macros, all the ...
I m using Microsoft Office 2003 and creating a bunch of template documents to standardize some tasks. I asked this on Superuser.com and got no response so I m thinking it s too program-y and hoping I ...
I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...
I need to ensure a Macro which works on Visio 2003 doesn t cause problems on lower versions of Visio: specifically because I m writing to a property which doesn t exist on lower versions of Visio. ...