Elusive "Operation is not allowed in this context" Error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Elusive "Operation is not allowed in this context" Error

  1. #1
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    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
    Last edited by Comintern; November 9th, 2005 at 03:54 PM. Reason: Typo

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    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 ...

    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
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Jan 2011
    Posts
    1

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Elusive "Operation is not allowed in this context" Error

    In the QUERY, around DATE fields, you need #

    Code:
    # datein #
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    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.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Elusive "Operation is not allowed in this context" Error

    And why add this to somebody ELSE's post about a different problem?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center