Query being deleted!

kidrobot

Registered User.
Local time
Today, 09:43
Joined
Apr 16, 2007
Messages
409
After I run this code my object query get completly wiped out (as in the SQL gets deleted). I have no clue why this happens, Here is my code... help!

Code:
Private Sub Print_Click()
If IsNull(MachineBox) Then

MsgBox "Please select a machine"

Else

    DoCmd.OutputTo acQuery, "MachinePrintOut", "MicrosoftExcelBiff8(*.xls)", "", False, "", 0
End If

End Sub
 
I see no reason why this code should remove any SQL or query??
 
Dude that's what I said. That is the only code that runs when I click that button. I'm so clueless to what is happening...
 
Simple Software Solutions

Ok lets try this

Code:
Private Sub Print_Click()
If IsNull(MachineBox) Then

MsgBox "Please select a machine"

Else

    DoCmd.OutputTo acQuery, "MachinePrintOut", "MicrosoftExcelBiff8(*.xls)", "", False, "", 0
[COLOR="Red"]    DoEvents
    DoCmd.OutputTo acQuery, "MachinePrintOut", "MicrosoftExcelBiff8(*.xls)", "", False, "", 0[/COLOR]
End If

End Sub

Place a breakpoint on the sub and step through the code. if it this command that is deleting the query then the second DoCmd statement should error.

If it does not then we shall look further afield.

CodeMaster::cool:
 
umm. how come when DoEvent is in the code it work and when I take it out the code will again delete my query??? that makes no sense
 
Simple Software Solutions

Hell, if adding the DoEvents line prevents it from deleting the query don't argue with it just leave it in.

David:cool:
 

Users who are viewing this thread

Back
Top Bottom