Hi guys, I originally posted this over on stackoverflow, but no replies, so I thought I would try in a more specialist forum. Link is here though... http://stackoverflow.com/questions/2...m-unexpectedly
To summarise my problem.
I use acViewPreview to open up my form in print preview mode after the textboxes within the form have been populated, ready for the user to print (I know about reports etc but a form was easier at the time). The code used to work perfectly, and I don't know what changed. Now, when the command runs the print preview mode has cleared all of the data from the form. Using the debug "meatball", I have narrowed it down to the use of the acViewPreview, and if I comment this line out, the data remains within the textboxes even after manually print previewing.
Anyone have any idea why this is suddenly happening or how I can fix it? A sample of my code is shown below
Code:
Private Sub generate_report_Click()'a subroutine to calculate the results of the selected date
Dim sdate As Date
Dim equipID As String, testString As String, msgString As String
Dim msgResponse As Integer
Dim hd_boo As Boolean
'check a date has been selected and if one has, inform the user of which tests were performed on that date
If IsNull([Forms]![Choose Calculation]!
[List_date].Column(0)) Then
MsgBox ("Please enter a valid date"): Exit Sub
Else
'set the string for the multiple criteria using information from the form
sdate = [Forms]![Choose Calculation]!
[List_date].Column(0)
equipID = [Forms]![Choose Calculation]![Equipment_ID]
'use format to confirm that the date types are correct
testString = "[Equipment ID] = '" & equipID & "' AND Format([Survey Date],""ddmmyyyy"") = " & Format(sdate, "ddmmyyyy")
If Not IsNull(DLookup("[ID]", "[Results_Hutt_Dig]", testString)) Then msgString = msgString & "- Digital Huttner" & vbCrLf: hd_boo = True
'confirm at least one test was found and inform user if not
If msgString = "" Then
MsgBox ("No tests results were found for the date selected, please select another date")
Exit Sub
Else
'ask user if they are happy with the tests performed
msgResponse = MsgBox("The following tests were performed on that date:" & vbCrLf & vbCrLf & msgString & vbCrLf & _
"Do you wish to proceed?", vbYesNo, "Tests Performed")
'if user says no, exit the sub
If msgResponse = 7 Then Exit Sub
End If
End If
'open the form to dump data in and clear any existing data
DoCmd.OpenForm "Results"
Call clear_resultsSheet
'dump generic data
[Forms]![results]![Text_date] = sdate
[Forms]![results]![Text_equipID] = equipID
'populate the report with the appropriate test results
If hd_boo = True Then Call huttdig_calculation(testString, equipID, sdate)
'open report page in print preview mode
DoCmd.OpenForm "Results", acViewPreview
End Sub
Thank you