Results 1 to 12 of 12

Thread: vb6 +Access db insert into entire collum

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    53

    vb6 +Access db insert into entire collum

    hi i have a form with :

    DataGrid1
    Adodc1
    textbox
    Command2


    on form load i have this code :


    Code:
    Private Sub Form_Load()
    
    Adodc1.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & (App.Path & "\Database\data.mdb") & ";Persist Security Info=False;Jet OLEDB:Database Password=password")
    Adodc1.RecordSource = "Select * from phonia"
    Set DataGrid1.DataSource = Adodc1
    
    End Sub
    i want at Private Sub Command2_Click()

    to insert into table phonia and colum 2008 the value of text1.text
    but i want to insert the value at entire collum

    sample : if text1.text = 2

    table phonia

    colum1 | 2008 |

    mike 2
    suzan 2
    nick 2
    george 2
    clif 2

    something like that.

    in entire colum 2008 i want to insert velue text1.text

    thanks

  2. #2
    Addicted Member Veritas2.0's Avatar
    Join Date
    May 2008
    Posts
    181

    Re: vb6 +Access db insert into entire collum

    I'm not really sure how you would do that with an data control although the SQL statement is simple enough.

    Code:
    UPDATE phonia SET 2008 = " & text1.text
    So many things I could say like don't use Bound Controls, your column names really shouldn't be just a number, and while it takes longer setting up connections without bound controls gives you alot more flexibility.
    Simple little bugs 13 : Me 1

    Law of Bugs - That one bug you missed will be found almost immediately, by your customer.

    I wonder if anyone has ever asked for a User Surly interface?

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: vb6 +Access db insert into entire collum

    Quote Originally Posted by Veritas2.0
    I'm not really sure how you would do that with an data control although the SQL statement is simple enough.

    Code:
    UPDATE phonia SET 2008 = " & text1.text
    So many things I could say like don't use Bound Controls, your column names really shouldn't be just a number, and while it takes longer setting up connections without bound controls gives you alot more flexibility.
    it is a sample project and sample names, i just make some tests
    dont realy matters what the name at the table you may give me some full example Private Sub Command2_Click()

    thanks

  4. #4
    Addicted Member Veritas2.0's Avatar
    Join Date
    May 2008
    Posts
    181

    Re: vb6 +Access db insert into entire collum

    Well If you are going to stick wth the bound controls I'm pretty sure what you are going to have to do is cycle through all the records and change the value in each one. I could be wrong though.

    I still recommend you just scrap the data controls and connect manually to the database.

    Code:
    Public myConnection As ADODB.connection
    
    Set myConnection = New ADODB.connection
        myConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & (App.Path & "\Database\data.mdb") & ";Persist Security Info=False;Jet OLEDB:Database Password=password"
    
        myConnection.Execute "UPDATE phonia SET 2008 = " & text2.Text
    Simple little bugs 13 : Me 1

    Law of Bugs - That one bug you missed will be found almost immediately, by your customer.

    I wonder if anyone has ever asked for a User Surly interface?

  5. #5
    Junior Member kasmot's Avatar
    Join Date
    Sep 2006
    Posts
    23

    Re: vb6 +Access db insert into entire collum

    Try this one:

    vb Code:
    1. Private Sub Command2_Click()
    2. Adodc1.RecordSource = "Select * from phonia" 'or any query that you want to edit
    3. Adodc1.Refresh
    4.  
    5. Adodc1.Recordset.MoveFirst
    6.  
    7. Do While Not Adodc1.Recordset.EOF
    8.  
    9. Adodc1.RecordSet.Edit
    10. Adodc1.Recordset.Fields("2008") = Text1.Text
    11. Adodc1.RecordSet.Update
    12. Adodc1.Refresh
    13.  
    14. Loop
    15.  
    16. End Sub
    http://worldinsights.blogspot.com/

    if your problem is resolved then mark it as resolved
    then rate the member that help you...

  6. #6
    Junior Member kasmot's Avatar
    Join Date
    Sep 2006
    Posts
    23

    Re: vb6 +Access db insert into entire collum

    Oh I for got

    You got to Insert this after the Adodc1.Recordset.Update code

    Adodc1.RecordSet.MoveNext

    Like this:


    vb Code:
    1. Adodc1.RecordSet.Edit
    2. Adodc1.Recordset.Fields("2008") = Text1.Text
    3. Adodc1.RecordSet.Update
    4. Adodc1.RecordSet.MoveNext
    5. Adodc1.Refresh
    http://worldinsights.blogspot.com/

    if your problem is resolved then mark it as resolved
    then rate the member that help you...

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: vb6 +Access db insert into entire collum

    Quote Originally Posted by kasmot
    Oh I for got

    You got to Insert this after the Adodc1.Recordset.Update code

    Adodc1.RecordSet.MoveNext

    Like this:


    vb Code:
    1. Adodc1.RecordSet.Edit
    2. Adodc1.Recordset.Fields("2008") = Text1.Text
    3. Adodc1.RecordSet.Update
    4. Adodc1.RecordSet.MoveNext
    5. Adodc1.Refresh
    Method or data member not found : Adodc1.Recordset.Edit !
    i think that Edit method doesn't exist in ADO
    Last edited by Chrisad; Aug 6th, 2008 at 01:00 AM.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: vb6 +Access db insert into entire collum

    All these troubles are because of using bound controls as mentioned earlier. You will save yourself alot of time and headaches by switching to pure ADO code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    53

    Re: vb6 +Access db insert into entire collum

    so there no any other option to do that ?

    thanks

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

    Re: vb6 +Access db insert into entire collum

    There are other options (including getting bound controls working), but they generally need much more effort to write, waste time/memory when running, and fewer people are able to help you - the people who help the most with database questions are unlikely to be much use.

    You should be following the suggestions Veritas2.0 made, and I'd recommend reading the link in post #2, as it contains several reasons why that is the way to go.

  11. #11
    Lively Member
    Join Date
    Mar 2010
    Posts
    67

    Re: vb6 +Access db insert into entire collum

    byee

  12. #12
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: vb6 +Access db insert into entire collum

    Quote Originally Posted by vb6beginer View Post
    byee
    Why did you bump this thread?!?

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