Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. newbie question on updating Access mdb tables

newbie question on updating Access mdb tables

Scheduled Pinned Locked Moved Visual Basic
questionannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john126
    wrote on last edited by
    #1

    I am new to mdb data bases and trying to copy data from a column in one table to a column in another table. Recently I wrote a short program to correct the data in one table of several mdb files. Below is the code I was using which works fine.

            'removes unwanted characters from Optional Info23 
            Dim OpInfo23\_upd As New OleDbCommand
            OpInfo23\_upd.CommandText = \_
                "UPDATE OP\_INFO SET OPINFO23 = mid(OPINFO23,'2','8') & mid(OPINFO23,'11','2') WHERE OPINFO23 > ''"
            OpInfo23\_upd.Connection = conn
            OpInfo23\_upd.ExecuteNonQuery()
            'sets flag character in Optional Info25 
            Dim OpInfo25\_upd As New OleDbCommand
            OpInfo25\_upd.CommandText = \_
                "UPDATE OP\_INFO SET OPINFO25 = mid(OPINFO23,'1','1')"
            OpInfo25\_upd.Connection = conn
            OpInfo25\_upd.ExecuteNonQuery()
    

    Now I am attempting to add the code to copy the data from the NAME column in the required information table (REQ_INFO) to the OPINFO29 column in the optional information table (OP_INFO). I tried the code below, but it generates an exception. Is it possible to update the table directly from another table?

            Dim OpInfo29\_upd As New OleDbCommand
            OpInfo29\_upd.CommandText = \_
                "UPDATE OP\_INFO SET OPINFO29 = REQ\_INFO.NAME WHERE OP\_INDEX = REQ\_INFO.REQ\_INDEX"
            OpInfo29\_upd.Connection = conn
            OpInfo29\_upd.ExecuteNonQuery()
    
    D L 2 Replies Last reply
    0
    • J john126

      I am new to mdb data bases and trying to copy data from a column in one table to a column in another table. Recently I wrote a short program to correct the data in one table of several mdb files. Below is the code I was using which works fine.

              'removes unwanted characters from Optional Info23 
              Dim OpInfo23\_upd As New OleDbCommand
              OpInfo23\_upd.CommandText = \_
                  "UPDATE OP\_INFO SET OPINFO23 = mid(OPINFO23,'2','8') & mid(OPINFO23,'11','2') WHERE OPINFO23 > ''"
              OpInfo23\_upd.Connection = conn
              OpInfo23\_upd.ExecuteNonQuery()
              'sets flag character in Optional Info25 
              Dim OpInfo25\_upd As New OleDbCommand
              OpInfo25\_upd.CommandText = \_
                  "UPDATE OP\_INFO SET OPINFO25 = mid(OPINFO23,'1','1')"
              OpInfo25\_upd.Connection = conn
              OpInfo25\_upd.ExecuteNonQuery()
      

      Now I am attempting to add the code to copy the data from the NAME column in the required information table (REQ_INFO) to the OPINFO29 column in the optional information table (OP_INFO). I tried the code below, but it generates an exception. Is it possible to update the table directly from another table?

              Dim OpInfo29\_upd As New OleDbCommand
              OpInfo29\_upd.CommandText = \_
                  "UPDATE OP\_INFO SET OPINFO29 = REQ\_INFO.NAME WHERE OP\_INDEX = REQ\_INFO.REQ\_INDEX"
              OpInfo29\_upd.Connection = conn
              OpInfo29\_upd.ExecuteNonQuery()
      
      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      And what is the exception message that is thrown?

      Dave Don't forget to rate messages!
      Find Me On: Web|Facebook|Twitter|LinkedIn
      Waving? dave.m.auld[at]googlewave.com

      J 1 Reply Last reply
      0
      • D DaveAuld

        And what is the exception message that is thrown?

        Dave Don't forget to rate messages!
        Find Me On: Web|Facebook|Twitter|LinkedIn
        Waving? dave.m.auld[at]googlewave.com

        J Offline
        J Offline
        john126
        wrote on last edited by
        #3

        No value given for one or more required parameters.

        1 Reply Last reply
        0
        • J john126

          I am new to mdb data bases and trying to copy data from a column in one table to a column in another table. Recently I wrote a short program to correct the data in one table of several mdb files. Below is the code I was using which works fine.

                  'removes unwanted characters from Optional Info23 
                  Dim OpInfo23\_upd As New OleDbCommand
                  OpInfo23\_upd.CommandText = \_
                      "UPDATE OP\_INFO SET OPINFO23 = mid(OPINFO23,'2','8') & mid(OPINFO23,'11','2') WHERE OPINFO23 > ''"
                  OpInfo23\_upd.Connection = conn
                  OpInfo23\_upd.ExecuteNonQuery()
                  'sets flag character in Optional Info25 
                  Dim OpInfo25\_upd As New OleDbCommand
                  OpInfo25\_upd.CommandText = \_
                      "UPDATE OP\_INFO SET OPINFO25 = mid(OPINFO23,'1','1')"
                  OpInfo25\_upd.Connection = conn
                  OpInfo25\_upd.ExecuteNonQuery()
          

          Now I am attempting to add the code to copy the data from the NAME column in the required information table (REQ_INFO) to the OPINFO29 column in the optional information table (OP_INFO). I tried the code below, but it generates an exception. Is it possible to update the table directly from another table?

                  Dim OpInfo29\_upd As New OleDbCommand
                  OpInfo29\_upd.CommandText = \_
                      "UPDATE OP\_INFO SET OPINFO29 = REQ\_INFO.NAME WHERE OP\_INDEX = REQ\_INFO.REQ\_INDEX"
                  OpInfo29\_upd.Connection = conn
                  OpInfo29\_upd.ExecuteNonQuery()
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I think you need to do an inner join on the tables. Like:

          UPDATE OP_INFO
          INNER JOIN REQ_INFO ON OP_INFO.OP_INDEX = REQ_INFO.REQ_INDEX
          SET OP_INFO.OPINFO29 = [REQ_INFO].[NAME];

          It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

          modified on Thursday, June 17, 2010 5:20 PM

          J 1 Reply Last reply
          0
          • L Lost User

            I think you need to do an inner join on the tables. Like:

            UPDATE OP_INFO
            INNER JOIN REQ_INFO ON OP_INFO.OP_INDEX = REQ_INFO.REQ_INDEX
            SET OP_INFO.OPINFO29 = [REQ_INFO].[NAME];

            It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

            modified on Thursday, June 17, 2010 5:20 PM

            J Offline
            J Offline
            john126
            wrote on last edited by
            #5

            That worked perfectly. Thank you

            L 1 Reply Last reply
            0
            • J john126

              That worked perfectly. Thank you

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Great. I had the table name wrong on the left-hand side of the SET but fixed it! :-O

              It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups