Results 1 to 5 of 5

Thread: runtimeerror 91

  1. #1
    Join Date
    Feb 2004
    Posts
    33

    Question Unanswered: runtimeerror 91

    I am running the following code and it shows the run-time error 91 "Object variable or with block variable not set". After hit the debug, it will highlight the

    !Complainant = Me!Complainant

    Please help!!! Thankssss

    Option Compare Database
    Option Explicit
    -------------------------------------------------------------------------------
    Private Sub Form_Open(Cancel As Integer)
    DoCmd.GoToRecord acDataForm, "Complaint Master Form", acNewRec, 1
    End Sub
    ---------------------------------------------------------------------------------

    Private Sub WTN_AfterUpdate()

    Dim rsp, SQLText
    Dim strWTN As String
    Dim db As DAO.Database, USERID As DAO.Recordset, tblComplaint As DAO.TableDef

    Set db = CurrentDb
    strWTN = CStr(WTN)
    SQLText = "Select [MasterUserIDTable].[USER-ID]" _
    & "From [MasterUserIDTable]" _
    & "Where [MasterUserIDTable].[USER-ID] = '" & strWTN & "'"
    Set USERID = db.OpenRecordset(SQLText)
    'Set tblComplaint = db.OpenRecordset("Complaint Master Table", dbOpenTable)


    If USERID.RecordCount <> 0 Then
    With tblComplaint

    !Complainant = Me!Complainant
    ![New WTN] = 0
    ![Complaint Number] = Me![Complaint Number]
    ![Complaint Status] = Me![Complaint Status]
    ![Complaint Reason] = Me![Complaint Reason]
    ![Date Written] = Me![Date Written]
    ![Date Received] = Me![Date Received]
    ![Date Resolved] = Me![Date Resolved]
    !PUC = Me!PUC
    ![PUC Date] = Me![PUC Date]
    !FCC = Me!FCC
    ![FCC Date] = Me![FCC Date]
    !AG = Me!AG
    ![AG Date] = Me![AG Date]
    !BBB = Me!BBB
    ![BBB Date] = Me![BBB Date]
    ![LCR Attorney] = Me![LCR Attorney]
    ![LCR Attorney Name] = Me![LCR Attorney Name]
    ![LCR Attorney Date] = Me![LCR Attorney Date]
    ![Handle By:] = Me![Handle By]
    ![Origin of Complaint] = Me![Origin of Complaint]
    ![IC Number] = Me![IC Number]
    ![PUC Number] = Me![PUC Number]
    ![Awaiting Correspondence] = Me![Awaiting Correspondence]
    ![company] = Me![company]

    End With


    ElseIf rsp = MsgBox("This WTN is not in Table. Do You Still Want to Continue?", vbYesNo) Then


    If rsp = vbYes Then
    MsgBox ("Please make sure the WTN is the right one!")

    With tblComplaint

    !Complainant = Me!Complainant
    ![New WTN] = 1
    ![Complaint Number] = Me![Complaint Number]
    ![Complaint Status] = Me![Complaint Status]
    ![Complaint Reason] = Me![Complaint Reason]
    ![Date Written] = Me![Date Written]
    ![Date Received] = Me![Date Received]
    ![Date Resolved] = Me![Date Resolved]
    !PUC = Me!PUC
    ![PUC Date] = Me![PUC Date]
    !FCC = Me!FCC
    ![FCC Date] = Me![FCC Date]
    !AG = Me!AG
    ![AG Date] = Me![AG Date]
    !BBB = Me!BBB
    ![BBB Date] = Me![BBB Date]
    ![LCR Attorney] = Me![LCR Attorney]
    ![LCR Attorney Name] = Me![LCR Attorney Name]
    ![LCR Attorney Date] = Me![LCR Attorney Date]
    ![Handle By:] = Me![Handle By]
    ![Origin of Complaint] = Me![Origin of Complaint]
    ![IC Number] = Me![IC Number]
    ![PUC Number] = Me![PUC Number]
    ![Awaiting Correspondence] = Me![Awaiting Correspondence]
    ![company] = Me![company]

    End With
    Exit Sub


    ElseIf rsp = vbNo Then

    Exit Sub

    End If
    End If
    End Sub

  2. #2
    Join Date
    Feb 2004
    Posts
    37
    Does Me!Complainant exist on the form? Is it enabled? Visible?

  3. #3
    Join Date
    Feb 2004
    Posts
    33
    Cheers for replying. The Complainant is on the form as a text box, in fact, all the rest are either text boxes or check boxex.

    And I think they are visible and enable.

    Please help! I have got stuck for a long time.


    Originally posted by brianb99999
    Does Me!Complainant exist on the form? Is it enabled? Visible?

  4. #4
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Re: runtimeerror 91

    Originally posted by leau
    I am running the following code and it shows the run-time error 91 "Object variable or with block variable not set". After hit the debug, it will highlight the

    !Complainant = Me!Complainant

    Please help!!! Thankssss

    Option Compare Database
    Option Explicit
    -------------------------------------------------------------------------------
    Private Sub Form_Open(Cancel As Integer)
    DoCmd.GoToRecord acDataForm, "Complaint Master Form", acNewRec, 1
    End Sub
    ---------------------------------------------------------------------------------

    Private Sub WTN_AfterUpdate()

    Dim rsp, SQLText
    Dim strWTN As String
    Dim db As DAO.Database, USERID As DAO.Recordset, tblComplaint As DAO.TableDef

    Set db = CurrentDb
    strWTN = CStr(WTN)
    SQLText = "Select [MasterUserIDTable].[USER-ID]" _
    & "From [MasterUserIDTable]" _
    & "Where [MasterUserIDTable].[USER-ID] = '" & strWTN & "'"
    Set USERID = db.OpenRecordset(SQLText)
    'Set tblComplaint = db.OpenRecordset("Complaint Master Table", dbOpenTable)


    If USERID.RecordCount <> 0 Then
    With tblComplaint

    !Complainant = Me!Complainant
    ![New WTN] = 0
    ![Complaint Number] = Me![Complaint Number]
    ![Complaint Status] = Me![Complaint Status]
    ![Complaint Reason] = Me![Complaint Reason]
    ![Date Written] = Me![Date Written]
    ![Date Received] = Me![Date Received]
    ![Date Resolved] = Me![Date Resolved]
    !PUC = Me!PUC
    ![PUC Date] = Me![PUC Date]
    !FCC = Me!FCC
    ![FCC Date] = Me![FCC Date]
    !AG = Me!AG
    ![AG Date] = Me![AG Date]
    !BBB = Me!BBB
    ![BBB Date] = Me![BBB Date]
    ![LCR Attorney] = Me![LCR Attorney]
    ![LCR Attorney Name] = Me![LCR Attorney Name]
    ![LCR Attorney Date] = Me![LCR Attorney Date]
    ![Handle By:] = Me![Handle By]
    ![Origin of Complaint] = Me![Origin of Complaint]
    ![IC Number] = Me![IC Number]
    ![PUC Number] = Me![PUC Number]
    ![Awaiting Correspondence] = Me![Awaiting Correspondence]
    ![company] = Me![company]

    End With


    ElseIf rsp = MsgBox("This WTN is not in Table. Do You Still Want to Continue?", vbYesNo) Then


    If rsp = vbYes Then
    MsgBox ("Please make sure the WTN is the right one!")

    With tblComplaint

    !Complainant = Me!Complainant
    ![New WTN] = 1
    ![Complaint Number] = Me![Complaint Number]
    ![Complaint Status] = Me![Complaint Status]
    ![Complaint Reason] = Me![Complaint Reason]
    ![Date Written] = Me![Date Written]
    ![Date Received] = Me![Date Received]
    ![Date Resolved] = Me![Date Resolved]
    !PUC = Me!PUC
    ![PUC Date] = Me![PUC Date]
    !FCC = Me!FCC
    ![FCC Date] = Me![FCC Date]
    !AG = Me!AG
    ![AG Date] = Me![AG Date]
    !BBB = Me!BBB
    ![BBB Date] = Me![BBB Date]
    ![LCR Attorney] = Me![LCR Attorney]
    ![LCR Attorney Name] = Me![LCR Attorney Name]
    ![LCR Attorney Date] = Me![LCR Attorney Date]
    ![Handle By:] = Me![Handle By]
    ![Origin of Complaint] = Me![Origin of Complaint]
    ![IC Number] = Me![IC Number]
    ![PUC Number] = Me![PUC Number]
    ![Awaiting Correspondence] = Me![Awaiting Correspondence]
    ![company] = Me![company]

    End With
    Exit Sub


    ElseIf rsp = vbNo Then

    Exit Sub

    End If
    End If
    End Sub
    Looks like for starters you need to set your tabledef object.

    Set tblComplaint = db.Tabledefs("YourTableName")
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  5. #5
    Join Date
    Feb 2004
    Posts
    33

    Cool

    yeah. That is the reason I think. I tried in your way and it was through.

    Thank you very very much.

    Also I just simplified the code as the following:

    Private Sub WTN_AfterUpdate()

    Dim rsp, SQLText
    Dim strWTN As String


    Set db = CurrentDb
    strWTN = CStr(WTN)
    SQLText = "Select [MasterUserIDTable].[USER-ID]" _
    & "From [MasterUserIDTable]" _
    & "Where [MasterUserIDTable].[USER-ID] = '" & strWTN & "'"
    Set USERID = db.OpenRecordset(SQLText)


    If USERID.RecordCount <> 0 Then
    ChkWTN = False

    Else: rsp = MsgBox("This WTN is not in the UserIDTable. Do You Still Want to Continue?", vbYesNo)
    If rsp = vbYes Then
    ChkWTN = True
    End If
    End If

    End Sub

Posting Permissions

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