goldenorb82
08-24-2004, 11:01 AM
Hello,
I have a template report called "rpt1" in my MS Access database which i use to dynamically create reports from a query which is constructed by selections made in forms by the user. The whole system works great, but the caveat is that the report cannot be saved since it is used over and over everytime the user wants to create a report. The assumption is that the user must either Print out the report or look at it and then close without saving. Of course, these kinds of assumptions should not be made. Here is an example of my code:
*strQuery1 is contains the query which is passed from another module
Public strQuery1 As String
Public Sub GetReportInfo()
strQuery1 = mdlReport.strQuery
DoCmd.OpenReport "rpt1", acViewDesign
Dim rpt As Report
Dim txtNew As Access.TextBox
Dim labNew As Access.Label
Dim rs As DAO.Recordset
Dim lngTop As Long
Dim lngLeft As Long
Dim lblCol As Long
Dim i As Integer
Dim prevColwidth As Long
lngLeft = 0
lngTop = 0
Set rpt = Reports![rpt1]
Set rs = CodeDb().OpenRecordset(strQuery1)
rpt.RecordSource = strQuery1
prevColwidth = 0
Dim intArray(0 To 20) As Integer
intArray(0) = 0
Dim intArray2(0 To 20) As Integer
intArray2(0) = 0
lblCol = 0
' Print the page header for the report.
For i = 0 To rs.Fields.Count - 1
'Test this code:
Set labNew = CreateReportControl(rpt.name, acLabel, acPageHeader, _
, mdlReport.strArray1(i + 1), , , , lngTop)
labNew.Left = lblCol
labNew.SizeToFit
labNew.FontUnderline = True
lblCol = lblCol + 600 + labNew.Width
intArray(i + 1) = lblCol
intArray2(i) = labNew.Width
Next
' Create the column depending on the number of fields selected in reportQuery.
' Assign the column value to new created column.
For i = 0 To rs.Fields.Count - 1
' Create new text box control and size to fit data.
Set txtNew = CreateReportControl(rpt.name, acTextBox, _
acDetail, , , , lngTop)
txtNew.Left = intArray(i)
txtNew.Width = intArray2(i)
txtNew.ControlSource = rs(i).name
' Modify the left margin depending on the number of columns
' and the size of each column.
prevColwidth = prevColwidth + txtNew.Width
Next
'To save the modification to the report, uncomment the following line of code:
'DoCmd.Save
' View the generated report.
DoCmd.OpenReport "rpt1", acViewPreview
' This opens the report in preview.
End Sub
My question is: is there anyway of bypassing the "Do you want to save changes to "rpt1" yes/no" msgbox that pops up automatically when anything in microsoft software is closed? Or is there another way to tackle this problem alltogether?
thanks
I have a template report called "rpt1" in my MS Access database which i use to dynamically create reports from a query which is constructed by selections made in forms by the user. The whole system works great, but the caveat is that the report cannot be saved since it is used over and over everytime the user wants to create a report. The assumption is that the user must either Print out the report or look at it and then close without saving. Of course, these kinds of assumptions should not be made. Here is an example of my code:
*strQuery1 is contains the query which is passed from another module
Public strQuery1 As String
Public Sub GetReportInfo()
strQuery1 = mdlReport.strQuery
DoCmd.OpenReport "rpt1", acViewDesign
Dim rpt As Report
Dim txtNew As Access.TextBox
Dim labNew As Access.Label
Dim rs As DAO.Recordset
Dim lngTop As Long
Dim lngLeft As Long
Dim lblCol As Long
Dim i As Integer
Dim prevColwidth As Long
lngLeft = 0
lngTop = 0
Set rpt = Reports![rpt1]
Set rs = CodeDb().OpenRecordset(strQuery1)
rpt.RecordSource = strQuery1
prevColwidth = 0
Dim intArray(0 To 20) As Integer
intArray(0) = 0
Dim intArray2(0 To 20) As Integer
intArray2(0) = 0
lblCol = 0
' Print the page header for the report.
For i = 0 To rs.Fields.Count - 1
'Test this code:
Set labNew = CreateReportControl(rpt.name, acLabel, acPageHeader, _
, mdlReport.strArray1(i + 1), , , , lngTop)
labNew.Left = lblCol
labNew.SizeToFit
labNew.FontUnderline = True
lblCol = lblCol + 600 + labNew.Width
intArray(i + 1) = lblCol
intArray2(i) = labNew.Width
Next
' Create the column depending on the number of fields selected in reportQuery.
' Assign the column value to new created column.
For i = 0 To rs.Fields.Count - 1
' Create new text box control and size to fit data.
Set txtNew = CreateReportControl(rpt.name, acTextBox, _
acDetail, , , , lngTop)
txtNew.Left = intArray(i)
txtNew.Width = intArray2(i)
txtNew.ControlSource = rs(i).name
' Modify the left margin depending on the number of columns
' and the size of each column.
prevColwidth = prevColwidth + txtNew.Width
Next
'To save the modification to the report, uncomment the following line of code:
'DoCmd.Save
' View the generated report.
DoCmd.OpenReport "rpt1", acViewPreview
' This opens the report in preview.
End Sub
My question is: is there anyway of bypassing the "Do you want to save changes to "rpt1" yes/no" msgbox that pops up automatically when anything in microsoft software is closed? Or is there another way to tackle this problem alltogether?
thanks