Results 1 to 8 of 8

Thread: error updating access database using visual basic

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Location
    india, mysore
    Posts
    11

    Question error updating access database using visual basic

    hi everybody
    i am trying to access a database and update the changes..
    Here is the code...
    Code:
    Option Explicit
    Dim c As New adodb.Connection
    Dim cn As New adodb.Connection
    Dim cm As adodb.Command
    Dim rsnew2 As New adodb.Recordset
    Dim rsnew3 As New adodb.Recordset
      
    Private Sub cmd_close_Click()
    Unload.me
    End Sub
     
    Private Sub cmd_edit_Click()
    rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
    If text1.Text = "" Then
    MsgBox " enter the company name"
    text1.SetFocus
    rsnew3.Fields("text1") = text1.Text
     End If
    If text2.Text = "" Then
    MsgBox " enter the company address"
    text2.SetFocus
    rsnew3.Fields("text2") = text2.Text
    End If
    rsnew3.Update
    MsgBox " add new successful ", vbInformation, "successful"
     
    End Sub
     
    Private Sub Form_Load()
    Dim cs As String
    c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
    rsnew2.Open "select * from company", c, adOpenDynamic
    Me.text1.Text = rsnew2(2)
    Me.text2.Text = rsnew2(3)
     
    End Sub
    I am getting message that "edit is successful", but its not updating in database..
    What should i do ????
    Last edited by Hack; Feb 26th, 2008 at 07:31 AM. Reason: Added Code Tags

  2. #2
    Addicted Member
    Join Date
    Jul 2007
    Posts
    146

    Re: error updating access database using visual basic

    I am getting message that "edit is successful", but its not updating in database..
    What should i do ????
    Hi,

    I don't see you closing the database connection, just closing you're app. I think the data is only actually written when the database is properly closed, but could be way of line. I don't know that much about databases.

    HTH
    Jottum™
    XpVistaControls , (transparent) usercontrols for XP, Vista and 7 with W2K legacy support.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: error updating access database using visual basic

    Open up your database.

    Are the records there?

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Location
    india, mysore
    Posts
    11

    Question Re: error updating access database using visual basic

    Ya data are there in database and i even tried closing record set .. But no difference

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: error updating access database using visual basic

    Quote Originally Posted by vikas1111
    Ya data are there in database
    So, they are in the database, which means that this
    Quote Originally Posted by vikas1111
    but its not updating in database..
    really isn't true.

    As such, what is the issue that you need to address?

  6. #6
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: error updating access database using visual basic

    Quote Originally Posted by vikas1111

    Private Sub cmd_edit_Click()
    rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic

    'If "Text1.text" is a null string ????, then fields "Text1" = empty
    If text1.Text = "" Then
    MsgBox " enter the company name"
    text1.SetFocus
    rsnew3.Fields("text1") = text1.Text
    End If

    'If "Text2.text" is a null string ????, then fields "Text2" = empty
    If text2.Text = "" Then
    MsgBox " enter the company address"
    text2.SetFocus
    rsnew3.Fields("text2") = text2.Text
    End If

    rsnew3.Update
    MsgBox " add new successful ", vbInformation, "successful"

    End Sub
    I think it won't update any field, if the msgbox " add new successfull " shown...

    Try this code :
    Code:
    Private Sub cmd_edit_Click()
    rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
    
    If text1.Text = "" Then
       MsgBox " enter the company name"
       Text1.SetFocus
    End If
    
    If text2.Text = "" Then
       MsgBox " enter the company address"
       Text2.SetFocus
    End If
    
    rsnew3.Fields("text2") = text2.Text
    rsnew3.Fields("text1") = text1.Text
    rsnew3.Update
    
    MsgBox " add new successful ", vbInformation, "successful"
    
    End Sub

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: error updating access database using visual basic

    Probably the fact that all that's being done is the FIRST record is being updated.... no new records are being added. The recordset is being opened and the fields Text1 and Text2 are being updated..... and that's it... mean while, you should be doing your data checks BEFORE you open the data.... doing them inline like that will cause problems in the long run.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Location
    india, mysore
    Posts
    11

    Question Re: error updating access database using visual basic

    Quote Originally Posted by Hack
    So, they are in the database, which means that thisreally isn't true.

    As such, what is the issue that you need to address?


    Fine .. I am accessing data which are already stored in the database.. I need to access them and update..and save the changes made to the accessed data.. The error in the program is , i am getting message "Update successful " but once i open database and see, the records are same as earlier , no updation takes place...

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