
Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> In my A2K app, there is a place where I get a runtime error. But if I go
> through that section in break mode, the error disappears.
[quoted text clipped - 20 lines]
>
> Thank you for any input.
Allen, thank you for replying. My code doesn't involve any recalculations,
but I think your answer must point to the problem. As you say, there must be
something in my code where Access is "catching up" in break mode. Here is an
overview of my code (and this has to do with writing letters):
' One form1, there is a command button that you click to open form2
Private Sub Command_Click()
DoCmd.OpenForm "form2", , , , acFormAdd, acDialog, newdata
Response = acDataErrAdded
Sub AddToListOfRecentLetters
End Sub
'form2 has several listboxes of return addresses
'names of addresses, and
'a textbox where you give the letter a name for saving
'there is a command button on form2 Captioned "WRITE LETTER"
'clicking this button opens Word by Automation and fills in Bookmarks
'with information from the listboxes.
'As to the name you are giving the letter (to prevent duplicate names)
'there is a local table containing a counter. A sub routine picks up the
'number in the table, adds that number at the end of the name, and increments
'the table by one. (I use a Long variable type for this)
'Access "knows" there is a Word Document open because of a
"While ... Wend loops that keeks looping as long as the Document Exists
'when the Word Document is closed, the Document
'no longer exists and this kicks you out of the While ... Wend
'to close form2
On Error GoTo CloseForm2
While objWord.IsObjectValid(objWdDoc)
Wend
CloseForm2:
DoCmd.Close
'You are now back to form1, and the next line of form1
'calls a sub routine in the module
'(Sub AddToListOfRecentLetters) that inserts basic information
'about the letter (Addressee, File Name, Date of Letter)
'into a local table
Set rst = New ADODB.Recordset
With rst
.CursorLocation = adUseClient
.CursorType = adOpenKeyset ' page 254,256 of Dev. Handbook
.LockType = adLockOptimistic ' page 256
.Open "RecentLetters", CurrentProject.Connection
.addnew
!clientID = lngclientID
!LetterFileName = strWdDocName & "_" & cstr(lngDocumentID)
.Update
End With
rst.Close
The bug occurs where you try to add strWdDocName to the table, and the error
message says there is a type mismatch because strWdDocName is Null. This
variable is not null. When the letter was saved by Word automation, it saved
properly under this name. Somehow, this variable has been "wiped out."
So thinking along the lines of your suggestion, is there a problem with the
DoCmd.Close command happening too fast, or is there some problem getting the
document ID number out of the local table, and why would that be? It is as
if there is some subtle error that has occurred in an earlier line of the
code that finally triggers the crash on what should be an innocuous line of
code.
> Bruce, what event is this? And what is the line of code that errors?
>
[quoted text clipped - 32 lines]
> >
> > Thank you for any input.
Allen Browne - 11 Jun 2007 16:39 GMT
Bruce, I didn't go through that in detail, as I didn't follow the first Sub.
Perhaps:
a) Does you Command_Click need to save the record first?
b) Opening a form in dialog mode will pause Command_Click at this point
until the dialog is closed.
c) Response is not a declared variable. If you are not using Option
Explicit, it might help you track down the problem.
d) I did not understand the Sub instruction inside another sub.
Sorry: can't follow it at all.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Allen, thank you for replying. My code doesn't involve any
> recalculations,
[quoted text clipped - 117 lines]
>> > it
>> > should I consider?
Bruce Maston - 11 Jun 2007 19:55 GMT
Allen, I think you may have solved my problem.
I have declared
Public Response as Integer
in my module. "Response" is used over and over in my app as the value
retrieved from a message box. But I don't use Response in any other context,
and I don't update any recordsources or use it in conjunction with Requery.
Thus,
Response = acDataErrAdded
is unnecessary surplusage.
Your reply points out that my form1 is paused by acDialog, so there can't be
any need for Access to "catch up" while form2 is running. So maybe the
unnecessary use of Response is what is creating the subtle problem that is
crashing me several lines later.
Again, thank you in advance if this works!
> Bruce, I didn't go through that in detail, as I didn't follow the first Sub.
>
[quoted text clipped - 132 lines]
> >> > it
> >> > should I consider?