VB2005 Database question...

Discussion in 'OT Technology' started by menorevs, Jan 24, 2008.

  1. menorevs

    menorevs Chuck Crew

    Joined:
    Jun 29, 2001
    Messages:
    11,502
    Likes Received:
    0
    Location:
    Southern MD
    I am like a super noob when it comes to this, but I cannot figure this out. I will explain what I am trying to do.

    I have a record thats already created. I want to copy (clone) that record and open a new record with that information pasted. The only thing that will have to be changed is the Primary Key. Its like when you want to copy a user account in active directory

    Any help is appreciated! Thanks
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    are you performing this in sql or in code? what database?

    assuming sql, you can do it like this:

    INSERT INTO Users( Name, Title )
    SELECT Name, Title
    FROM Users
    WHERE Id = [id to clone]
     
  3. menorevs

    menorevs Chuck Crew

    Joined:
    Jun 29, 2001
    Messages:
    11,502
    Likes Received:
    0
    Location:
    Southern MD
    I guess I could do it in SQL, but I am doing it in code. Since I am pretty new at this, I dont think I will be tackling stored procedures anytime soon :)

    I was seeing if there was an eaiser way. I was looking up different options, like .copy or .clone but all that looks like if you want to copy tables, not records.

    What I am trying to do, I guess in psuedo code is

    Find record want to copy
    click CLONE
    opens up new form with all information but for the primary key since that is an indentity.

    Am I making any sense?
     
  4. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    notrly

    are you using DataSets?
     
  5. menorevs

    menorevs Chuck Crew

    Joined:
    Jun 29, 2001
    Messages:
    11,502
    Likes Received:
    0
    Location:
    Southern MD
    yes. I guess I will try to explain one more time, sorry about this.

    I have a database, called mydatabase.mdf. I have successfully connected my application to it. I can add, delete, more forward, back, etc.

    Now I have customers that order the same thing every single time, but maybe a slight differnce in the part. I have over 40 entries in my table, so to type over the same information over and over again makes no sense, kinda like my last post :)

    So I was wondering, if there was a way to select my customer, and with a button copy all information and open a new record with that information already filled out but for 1 key, which is the Identity key (which my primary key)

    I know there is simplier ways to do what im doing, with different tables linking together, but I want to do this first, and later on really dive into Parent/Child tables.

    I appreicate the help you are tryng to give :)
     
  6. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    it would be most easy to have the "copy" button run a select query to grab your "clone" info... Then run an insert query with the hyrbid clone/new data to add your record.

    To reduce SQL queries you could have a form with all fields present, then have a "populate" button run the select query, and the user can change the field(s) neccessary and push the "add" button. And they can repeat this over and over changing one or more fields and the select query only runs once.
     
  7. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Well with vba which is close to VB, it would be something like this:

    Code:
    with recset
         .addnew
         !FirstName = me!FirstName
         !LastName = me!LastName
         .update
    end with
    
    I've left out a bunch but you get the idea - you pull the data off of the open form and add that to a new record. Is that what you meant?
     
    Last edited: Jan 24, 2008
  8. menorevs

    menorevs Chuck Crew

    Joined:
    Jun 29, 2001
    Messages:
    11,502
    Likes Received:
    0
    Location:
    Southern MD
    Yea but I want that recordset to be open for any other changes I want to make. I dont want this to all run in the background and be finished.
     
  9. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Well copy the forms data into variables, open the new record, paste the variables into the form.
     
  10. menorevs

    menorevs Chuck Crew

    Joined:
    Jun 29, 2001
    Messages:
    11,502
    Likes Received:
    0
    Location:
    Southern MD
    It was long but it worked, thank you.

    And thank you everyone that gave me any information!
     

Share This Page