Results 1 to 13 of 13

Thread: replace old record to new record

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    209

    replace old record to new record

    guys help me with this!
    see this screenies...
    Attached Images Attached Images  

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: replace old record to new record

    will this help you....
    Code:
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source= " & App.Path & "\db1.mdb;Persist Security Info=False;Jet OLEDB:Database Password=pwd;"
        cn.Open
    
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM Table1 ", cn, adOpenForwardOnly, adLockReadOnly
    
    While Not rs.EOF
                if left(rs.fields("from_bus_id"),4)="S001" then   ' ~~~> please try to use table/field names without spaces or you can use underscore
                    rs.fields("phasing")="CN"    ' ~~~> new phasing
                    rs.update
                end if
        rs.MoveNext
    Wend
    rs.Close
    cn.Close
    Set rs = Nothing
    Set cn = Nothing
    You have to make some changes to the code.. like the database name , database password , etc... in the above code

    Good luck...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    209

    Re: replace old record to new record

    thanks for the urgent reply sir! i'll try this!

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: replace old record to new record

    Ok...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    209

    Re: replace old record to new record

    it really works sir!

    1 more sir, in this code..."If Left(rs.fields("From_Bus_ID"), 4) = "S003" Then"
    what if im using 5 or 6 characters example: s0010 or s00100... ca n you please help sir/

    anyway, is there possible to use input in textbox instead of coding in program in runtime? like in my previous post...

    thanks in advance sir!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    209

    Re: replace old record to new record

    it really works sir!

    1 more sir, in this code..."If Left(rs.fields("From_Bus_ID"), 4) = "S003" Then"
    what if im using 5 or 6 characters example: s0010 or s00100... ca n you please help sir/

    anyway, is there possible to use input in textbox instead of coding in program in runtime? like in my previous SS post...

    thanks in advance sir!

  7. #7
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: replace old record to new record

    S003-TPD0005
    We can extract the data before - using the below code....
    Also, i used txtPhase, which is a text box that contains the old phase...

    Code:
    if left(rs.fields("from_bus_id"),instr(1,rs.fields("from_bus_id"),"-")-1)=txtPhase.Text then
    Last edited by akhileshbc; Nov 13th, 2009 at 01:05 AM.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    209

    Re: replace old record to new record

    i can't understand sir...
    can u please explain in one by one because im still noob in VB..hehe

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: replace old record to new record

    Code:
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source= " & App.Path & "\db1.mdb;Persist Security Info=False;Jet OLEDB:Database Password=pwd;"
        cn.Open
    
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM Table1 ", cn, adOpenForwardOnly, adLockReadOnly
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    While Not rs.EOF       '~~~ loops through the recordset
               if left(rs.fields("from_bus_id"),instr(1,rs.fields("from_bus_id"),"-")-1)=txtSearch.Text then
                    
    rs.fields("phasing")=txtNewPhase.Text    ' ~~~> new phasing
                    rs.update
                end if
        rs.MoveNext
    Wend
    rs.Close
    cn.Close
    Set rs = Nothing
    Set cn = Nothing
    txtSearch is the text box which can be used to enter data like S003
    txtNewPhase is the text box which can be used to enter new phase like CN

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  10. #10
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: replace old record to new record

    eg: Consider S003-TPD0005

    The below code will give S003
    Code:
    left(rs.fields("from_bus_id"),instr(1,rs.fields("from_bus_id"),"-")-1)
    I hope you understand....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    209

    Re: replace old record to new record

    problem solved sir! it works perfectly...
    thanks sir!
    good day and GOD bless....

  12. #12
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: replace old record to new record

    problem solved sir! it works perfectly...
    thanks sir!
    good day and GOD bless....
    Happy to hear that...

    You can mark this thread as RESOLVED

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: replace old record to new record

    Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)

Posting Permissions

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



Click Here to Expand Forum to Full Width