File Error Message

y2k

Registered User.
Local time
Today, 17:56
Joined
Mar 11, 2002
Messages
36
Please can somebody help me. I have an access database which uses an AutoExec macro to run when it's opened. I runs some queries and then prints some reports. However, when I open it, the macro starts to run as normal, but then I get a windows error message saying it can't find the file and I have to use CTRL + ALT + DEL to end Access.

Please, can anybody help me? Why is this happening?
 
It is not clear from your discussion, so I will offer a guess.

You attempt to create a file in your macro.

Then you attempt to do something with the file, say PRINT it as an example.

But if you have warnings FALSE, you might miss the fact that the file creation failed or some other file dispostion step did something totally unexpected.

I would try to single-step the macro to check each step of the way to find out what is wrong. Have a window open to the directory folder where you are creating the file. Refresh it after each step of the macro.

Also, I would make sure that the file you are attempting to affect is the same exact name, type, and path as the file you created.

One other issue. When you use that AutoExec feature, you need to be aware of the default path in use at the time. If your file creation step doesn't specify a path portion, you create it in the current default path, which might not be the same as the path you get when you open Access from a shortcut or the Start menu.
 
Last edited:
Sorry, I did explain myself badly. For arguments sake, lets call the database access1.mdb. It runs make table queries and then prints some reports, the queries create the record source for the reports. This is not the problem.

The problem is that half way through running the queries I get an error message saying "can not find C:\database\access1.mdb, recheck the path.....". It's not the .ldb file it says that's missing, it is the actual database. Despite the fact that it's open. Why is this?

I've been running this database for months now without any problems. I createdan extra macro yesterday and added it into the "onNoData" property in each of the reports. Surely this couldn't have caused it though as it's hasn't even finished running the queries when it generates the error message.

Please help!!!!!
 
Last edited:
Why are you using macros in the no data event, what are you trying to do with them?
 
The macro cancels the report from printing if there is no data in the report to print
 
Since you are using at least some VBA code, I have to ask this question:

Do you ever open a database object ?

And if so, do you ever close it?

I wonder if you might have a .Close method applied to something that you ought not to have closed, thus confusing Access as to what it was talking to previously.


Just a guess, though. I've never seen that particular message myself, though I've seen my share of other nasty-grams from Gates & Co.
 
Actually, I'm not using any VBA. Althought I can see why you would think I am. I created a macro (and creatively called it onNoData!) with one action - CancelEvent. I then entered this into the On No Data property for each report. So it will execute the onNoData macro if there are no records in the source table.

Running the queries and printing the macros is also done in a macro, so I didn't have to use any VBA. Just to add to the twist, it's not doing it all the time now, which is good. But I'd like to find out what's causing it (if there really is anything that's causing it!) and eliminate it if at all possible.

I've often seen the message saying it could not find the .ldb file, but never the .mdb file I have to admit. I guess you're all out of ideas now? But thank you very much for your help.
 
Most of us wouldn't use a macro for this sort of operation, or any come to that other than an Autoexec there's no inbuilt error handling, much better to use vba.
 
Rich said:
Most of us wouldn't use a macro for this sort of operation, or any come to that other than an Autoexec there's no inbuilt error handling, much better to use vba.

I was using VBA but I had to create a seperate module for each report, and there's over 200! So I created a macro instead and used the CancelEvent action and put it in the On No Data report property. That way when the macro that prints the reprots is running, it'll only print the ones with data in them. Why would you not do this?
 
I can see why you want to avoid adding the same thing to 200 reports. But there is no better way to handle the NoData case than a little VBA code.

Perhaps you can try this approach...

In a report context, the Report_NoData event is pretty straightforward. It could be as simple as

Private Sub Report_NoData(Cancel as Integer)

Cancel = True

End Sub

So maybe you want to build one of these, then do a cut-and-paste operation to a file in Windows Notepad context (.txt file).

Then design each report one at a time and drop in the new routine.

Or, here's another thought...

If you really, REALLY, REALLY don't want to cut-and-paste 200 times, you can also do it through code. If you are the type who likes to experiment, the above case might be just what the doctor ordered (pardon the mild pun)...

You can open a module and write a function to insert the above into each report by using a For Each loop on the collection of all report documents.


Dim loLineNum as Long
Dim loLastLine as Long
Dim loColNumL as Long
Dim loColNumR as Long

{you will also need to declare a database object, report object, and module object. I'll leave that to you.}

. . .

Set {database-object} = CurrentDB()

For Each {report-object} in {database-object}.Containers!Reports.Documents

If {report-object}.HasModule Then
Set {module-object} = {report-object}.Module
Else
{report-object}.HasModule = True
Set {module-object} = {report-object}.Module
End If

{the above sequence, in English, is "if it has a module, point to it. If it doesn't have a module, make one and point to it."}

loLineNum = 0
loLastLine = 0
loColNumL = 0
loColNumR = 0

If Not {module-object}.Find "_NoData(", loLineNum, loColNumL, loLastLine, loColNumR, False, False, False then

loLineNum = {module-object}.CreateEventProc("NoData", {report-object}.Name)

{module-object}.InsertLines loLineNum+1, "{code to insert}"
{module-object}.InsertLines loLineNum+2, "{more code}"

Else

loLineNum = MsgBox( "Report " & {report-object}.Name & " already has a NoData Event", vbOKOnly, "Event Not Inserted")

End If 'end of IF NOT ...FIND

Next {report-object}


If you put that fragment inside a function, you could call it from a macro. It will find all your report objects, search each one for already having a NoData event, and if no such event exists, it creates one. The part with Else and the MsgBox call is optional, you could leave it out if you don't care to know that a particular report's class module already has a NoData event. Or, you might build this with the MsgBox present the first time and then take it out for later runs in case you build more reports and want to run this again later.

Before you attempt doing this at all, I strenuously advise you to read up on Module objects and the methods associated therewith. Also, try this on a copy of your database just in case it doesn't work quite right the first time.

Note that the CreateEventProc method will create an empty event routine for you. You won't need to create the line that declares the procedure or the line that ends it. You will only need to define the code body you want to add. Might be as simple as a single line, setting the Cancel variable to TRUE. Or, for you purists out there,... CInt(TRUE)

Finally, you really don't like VBA code, then don't even start this 'cause it will take a while to get it exactly right.
 

Users who are viewing this thread

Back
Top Bottom