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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyway to eliminate error system messages? 1

Status
Not open for further replies.

nakedbamboo

Technical User
Oct 8, 2003
36
US
I have a button that outputs a query to a saved file by asking the user where they would like to save it. The code is:

DoCmd.OutputTo acOutputQuery, "Search", acFormatXLS, FileName

If the user clicks cancel to saving it, a message comes back saying "Output was canceled." Is there any way to turn these types of messages off?
 
docmd.setwarnings false

Remember to set it back to true when you are finished with your command.

HTH,
Eric
 
Where would I put this line? I tried putting it right before the ouptut code, but I still get the message. The exact message is:

"The OutputTo Action Was Canceled"
OK


 
Try checking to see in the users input is blank. Something like this should work.


FileName= InputBox("Enter Path of file","Enter Path")
if FileName <> &quot;&quot; then
DoCmd.OutputTo acOutputQuery, &quot;Search&quot;, acFormatXLS, FileName
end if

I don't know what method you are using to get the path of the file name. If you post your code then I can give you a more specific example.

HTH,
Eric
 
Actually, that line of code is all I have and it makes the Windows Save dialog come up. It allows them to browse to a location and chose their own file name. I just have &quot;FileName&quot; as a string but never actually assign anything to it. I discovered that this caused the dialog to pop up. However, sometimes the search doesn't need to be saved so they click cancel. This causes the issue at hand.
 
In that case this should work.

On Error GoTo ErrorX
DoCmd.OutputTo acOutputQuery, &quot;Search&quot;, acFormatXLS
Exit Sub
ErrorX:
If Err.Number = 2501 Then
Exit Sub
Else
MsgBox Err.Number & &quot;-&quot; & Err.Description
End If
 
That worked great. Thanks. One question; you left of the &quot;FileName&quot; and it still worked, I was curious why that is not necessary? I could have sworn I tried it without the FileName once and it didn't worked.
 
The best answer I can give you is from the help file.

&quot;OutputFile Optional Variant. A string expression that's the full name, including the path, of the file you want to output the object to. If you leave this argument blank, Microsoft Access prompts you for an output file name.&quot;

HTH,
Eric
 
Eric, will the same code work for all system messages. I have a button, when pushed asked for three separate parameters and then puts a bunch of values in text boxes of a form. All three parameters are dates. I accidentally typed in 2003 instead of 11/2003 and received and error message and it took me to my code. I would like to eliminate the possibility of these kinds of errors.

However, I am not sure how to adjust your code to fit that circumstance. Can you help please? Thanks, JL
 
If you can go to thread 702-733372, I just posted the code for another question. Thanks, JL
 
How are you getting your dates? Input box, userform...?
You can trap any error but it seems that you actually need some sort of validation of your date input.
Eric
 
I assume since the report is tied to the query, when it opens the report, it automatically opens the query, which requires a parameter date to be answered; so it opens a parameter box for your input. It being Access, not me. I was going to create a command button, like find, and steal that error code, but was not sure it would be the &quot;correct&quot; thing to do. Thoughts?

This all may be a moot point now anyway, because I instead of putting in the year 8 times, I am going to try and make a message box that opens and allows my input of the year, and then the parameters can go to that place to get the code. Obviously I don't know where that place is because I am talking way over my head.

Any help is appreciated though. Thanks, JL
 
You can store the date in a public variable.
Add a module. In that module put these lines:

public xDate as date
function GetDate()
GetDate=xDate
end function

Then in your button's on click event add this code:

xDate = InputBox(&quot;Please enter a date.&quot;, &quot;Enter Date&quot;)
msgbox &quot;You have entered &quot; & xDate

In your query parameter you can call the variable by using the function GetDate.
example: GetDate()

HTH,
Eric
 
Eric, thanks for the help. It did open a window to get date, but I changed it to &quot;Please enter a year&quot;. It accepted the year, but then the window comes up saying &quot;You have entered 6/25/1905&quot;. I entered 2003. Also, can it be &quot;You have entered 6/25/1905, is this correct?&quot; with a correct or uncorrect button to rerun. I guess through an Iif statement. Any ideas? Thanks, JL
 
If you only need to enter the year you should store it as an integer. Change
public xDate as date
to
public xDate as integer

Then change you event code to propmt for a yes/no message box:
xDate = InputBox(&quot;Please enter a date.&quot;, &quot;Enter Date&quot;)
varYN = MsgBox(&quot;You have entered &quot; & xDate & &quot;,&quot; & vbCrLf & _
&quot;Is this correct?&quot;, vbYesNo, &quot;Correct Date?&quot;)
if varYN=6 then
'do something
else
'do something else
exit

HTH,
Eric
 
Okay, I did what you said. Two things:

VarYN=6 (what is six?)
the first 'do something I am assuming I need to change to something to get it... a light just came on.

I went back to my code and typed in loop. So, if the person said it was not the write day, they could go back and reenter the date. However, the code said I also needed Do. I looked up Do in the help, and I guess I am to brain dead to figure out how to incorporate it into my code. Sorry to be so dense.

Is that was the 'do somethings was for?

Thanks, JL
 
6 means Yes, 7 means No.

What I meant by &quot;Do something&quot; was just to run a procedure when Yes was returned from the message box. &quot;Do something else&quot; just means to run a procedure when no is selected.

Look up &quot;Do Loop&quot; in the help files. There is a pretty good example of how to set one up.

If you need any more help post exactly what you are trying to do and I'll see if I can provide more info.

HTH,
Eric
 
Eric, I have never done a Do..Loop. After looking at the examples you suggested and your code, I came up with the following:

Private Sub Form_Open(Cancel As Integer)
Dim Check
Check = Yes
Do While [VarYN = 7]
xDate = InputBox(&quot;Please enter a year.&quot;, &quot;Enter Date&quot;)
VarYN = MsgBox(&quot;You have entered &quot; & xDate & &quot;,&quot; & vbCrLf & _
&quot;Is this correct?&quot;, vbYesNo, &quot;Correct Date?&quot;)
If VarYN = 7 Then
Check = No
End If
Loop
Exit

It keeps giving me an error that a Do is expected. I have a Do so I do not understand why it does not see it. Help please. JL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top