Elusive "Operation is not allowed in this context" Error
I keep getting an error 3219, "Operation is not allowed in this context." in my error log that originates from the function below. Everywhere I look online, the only references to this error are for ADO, but there are no ADO objects acted on in the function. I also have no luck when I try to replicate the error (it only shows up about once every 200 or so runs). I'm pretty sure that it isn't originating in any of the called functions, because they have their own error handlers. Any ideas? Can Word throw this error for some reason?
Code:
Public Function CreateNotReins() As Boolean
Dim sToOpen As String, sDeceased As String, sDate As String, sPolicy As String
Dim sFace As String, sCeded As String
On Error GoTo ErrorHand
bOutputGo = False
With frmDeathClaim
sDeceased = Trim$(.txtFirstName.Text) & " " & Trim$(.txtLastName.Text)
sDate = .txtDOD.Text
If sDate = "NA" Then
sDate = "Not Available"
End If
sPolicy = .txtPolicyNum.Text
sFace = Format(.txtFace.Text, "$ #,###")
sCeded = "$ 0"
End With
sToOpen = gsPath & "\DeathClaim.tpl"
If oWord Is Nothing Then
Set oWord = New Word.Application
End If
Set oTemplate = oWord.Documents.Open(sToOpen)
With oTemplate
.Bookmarks("Name").Range.Text = sDeceased
.Bookmarks("Date").Range.Text = sDate
.Bookmarks("Number").Range.Text = sPolicy
.Bookmarks("Face").Range.Text = sFace
.Bookmarks("Ceded").Range.Text = sCeded
.Bookmarks("NotReins").Range.Text = "Policy is not reinsured."
End With
frmOutputOpts.Show (vbModal)
frmDeathClaim.Repaint
If bOutputGo = True Then
If PostProcess = True Then
CreateNotReins = True
End If
End If
ErrorHand:
If Err.Number <> 0 Then
sError = "Error number " & CStr(Err.Number) & "," & vbCrLf & Err.Description & "," & vbCrLf & _
"has occured in the CreateNotReins procedure."
Call ErrorLogger(Err.Number, Err.Description, "CreateNotReins", "sPolicy = " & sPolicy)
Err.Clear
Call MsgBox(sError, vbCritical + vbOKOnly, "Critical Error")
End If
End Function
Re: Elusive "Operation is not allowed in this context" Error
Have you tried turning off the error handlers, and running it until you get the error. This way you can check which line of code is returning the error.
Or you could put markers in the Function, and write out the marker to your log file, when it errors. These sometime help me Debug some of those lonnnnnggggggg subs we sometimes seem to end up with :D ...
From there your can trace the exact problem..
But it sounds more like a Word generated error. Probably a bit slow in opening the file..
Gremmy
Re: Elusive "Operation is not allowed in this context" Error
Hey am new here. Am having Problem with my code "Operation is not allow in this context" below is my code:
If gbtrr1.State <> adStateClosed Then gbtrr1.Close '---- I expect this line to have closed any open connection if there is any'
datein = Format(Date, "yyyy/MM/dd")
gbtrr1.open "select * from Tbluserslog where username ='" & UserName & "'and date_in ='" & datein & "'and (date_out is not null or date_out <>'')", GbtConn, adOpenDynamic, adLockBatchOptimistic
If gbtrr1.RecordCount > 0 Then
MsgBox "Sorry! Your Administrator(s) has Signed You Out. Contact Your IT ", vbCritical, App.title
gbtrr1.Close
End
Else
End If
please guys help me out. thank. never mind my english
Re: Elusive "Operation is not allowed in this context" Error
In the QUERY, around DATE fields, you need #
Re: Elusive "Operation is not allowed in this context" Error
The # is required if using Access but that would not cause the error given.
It looks like you are trying to perform recordset operations on a connection object which is a problem.
Re: Elusive "Operation is not allowed in this context" Error
And why add this to somebody ELSE's post about a different problem?