Trouble Defining and Updating Recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Proaccesspro
    New Member
    • Apr 2007
    • 132

    Trouble Defining and Updating Recordset

    I'm trying to update a field in a table with the value of a text box in a report. Here is what I have:

    Private Sub Report_Close()

    Dim rs As Recordset

    Set rs = CurrentDb.OpenR ecordset("OHPA Summary Report Table")

    rs.AddNew
    rs("Begining Balance") = [Text4]

    rs.Update

    End Sub


    When I run the code, I keep getting a type mismatch on the line where I set rs = currentdb....et c. ANY ideas??? Is there a better way to do this??
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by Proaccesspro
    I'm trying to update a field in a table with the value of a text box in a report. Here is what I have:

    Private Sub Report_Close()

    Dim rs As Recordset

    Set rs = CurrentDb.OpenR ecordset("OHPA Summary Report Table")

    rs.AddNew
    rs("Begining Balance") = [Text4]

    rs.Update

    End Sub


    When I run the code, I keep getting a type mismatch on the line where I set rs = currentdb....et c. ANY ideas??? Is there a better way to do this??
    Hi. There is more than one kind of recordset, and unfortunately they have different methods and properties. As it is the Access DAO-type recordset you are using your problems should be resolved if you qualify your DIM as
    [code=vb]Dim rs as DAO.Recordset[/code]
    If the DAO qualifer is not recognised you will need to set a reference to the Microsoft DAO object library via Tools, references in the VB editor.

    -Stewart

    Comment

    • Proaccesspro
      New Member
      • Apr 2007
      • 132

      #3
      Originally posted by Stewart Ross Inverness
      Hi. There is more than one kind of recordset, and unfortunately they have different methods and properties. As it is the Access DAO-type recordset you are using your problems should be resolved if you qualify your DIM as
      [code=vb]Dim rs as DAO.Recordset[/code]
      If the DAO qualifer is not recognised you will need to set a reference to the Microsoft DAO object library via Tools, references in the VB editor.

      -Stewart

      Yep, it dod not like the DOA qualifier. I tried to get to the references option but it is greyed out........

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Originally posted by Proaccesspro
        Yep, it dod not like the DOA qualifier. I tried to get to the references option but it is greyed out........
        Perhaps you didn't stop the debugger (by pressing the little rectangular reset button) before trying to set the reference??

        Comment

        • Proaccesspro
          New Member
          • Apr 2007
          • 132

          #5
          Originally posted by Stewart Ross Inverness
          Perhaps you didn't stop the debugger (by pressing the little rectangular reset button) before trying to set the reference??
          Yes, you're right...seems to work OK now....One last question, what command can I use to delete all records in a table?

          Comment

          • Stewart Ross
            Recognized Expert Moderator Specialist
            • Feb 2008
            • 2545

            #6
            Originally posted by Proaccesspro
            Yes, you're right...seems to work OK now....One last question, what command can I use to delete all records in a table?
            Well, living dangerously you can use
            [code=sql]Docmd.RunSQL "DELETE * FROM yourtablename;"[/code]
            You would need to turn warnings off and on before and after using [code=vb]Docmd.Setwarnin gs False (or True)[/code]
            or a similar method.

            -Stewart

            Comment

            • Proaccesspro
              New Member
              • Apr 2007
              • 132

              #7
              Originally posted by Stewart Ross Inverness
              Well, living dangerously you can use
              [code=sql]Docmd.RunSQL "DELETE * FROM yourtablename;"[/code]
              You would need to turn warnings off and on before and after using [code=vb]Docmd.Setwarnin gs False (or True)[/code]
              or a similar method.

              -Stewart
              It does not like it. Says I have a syntax error.

              DoCmd.RunSQL "DELETE * FROM DEHP Summary Report Table;"

              Comment

              • Stewart Ross
                Recognized Expert Moderator Specialist
                • Feb 2008
                • 2545

                #8
                Originally posted by Proaccesspro
                It does not like it. Says I have a syntax error.

                DoCmd.RunSQL "DELETE * FROM DEHP Summary Report Table;"
                Hi. Where the name of a field or table has spaces in it you must enclose it in square brackets.
                [code=sql]DoCmd.RunSQL "DELETE * FROM [DEHP Summary Report Table];"[/code]
                -Stewart

                Comment

                • Proaccesspro
                  New Member
                  • Apr 2007
                  • 132

                  #9
                  Originally posted by Stewart Ross Inverness
                  Hi. Where the name of a field or table has spaces in it you must enclose it in square brackets.
                  [code=sql]DoCmd.RunSQL "DELETE * FROM [DEHP Summary Report Table];"[/code]
                  -Stewart
                  B-I-N-G-O!!! Thanks!

                  Comment

                  Working...