Results 1 to 11 of 11

Thread: [RESOLVED] Updateing Access Database

  1. #1

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Resolved [RESOLVED] Updateing Access Database

    Hi...
    I have several forms and I need to update an MS Access Database from a form that does not contain the database ref. I've tried this on the form that doesn't contain the record set:
    Code:
    Patient_Info2.datPrimaryRS.Recordset.UpdateBatch adAffectAll
    , but when I go back to the form WITH the record set (Patient_Info2) and select another record I get the error "Operation was Cancel" with the record number that was suppose to be updated in the title of the message box .

    If I use my "update record" command button on the Patient_Info2 form it saves it ok (button executes the same code as above) and then I can go to the next record. I need to make this automatic (from my other form) as well as with the command button.

    What am I doing wrong???
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Updateing Access Database

    Quote Originally Posted by aa9gg View Post
    Hi...
    I have several forms and I need to update an MS Access Database from a form that does not contain the database ref. I've tried this on the form that doesn't contain the record set:
    Code:
    Patient_Info2.datPrimaryRS.Recordset.UpdateBatch adAffectAll
    , but when I go back to the form WITH the record set (Patient_Info2) and select another record I get the error "Operation was Cancel" with the record number that was suppose to be updated in the title of the message box .

    If I use my "update record" command button on the Patient_Info2 form it saves it ok (button executes the same code as above) and then I can go to the next record. I need to make this automatic (from my other form) as well as with the command button.

    What am I doing wrong???
    Could you post the entire code that updates the recordset? How have you opened the recordset?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Updateing Access Database

    Good point...I don't see where it is actually opened! I built the form using the database wizard in VB6. It is defined in an Adodc control. The update code is:

    Code:
    Private Sub cmdUpdate_Click()
      On Error GoTo UpdateErr
      datPrimaryRS.Recordset.UpdateBatch adAffectAll
      Exit Sub
    UpdateErr:
      MsgBox Err.Description
    End Sub
    So is it REALLY opened????
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  4. #4
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Updateing Access Database

    Quote Originally Posted by aa9gg View Post
    Good point...I don't see where it is actually opened! I built the form using the database wizard in VB6. It is defined in an Adodc control. The update code is:

    Code:
    Private Sub cmdUpdate_Click()
      On Error GoTo UpdateErr
      datPrimaryRS.Recordset.UpdateBatch adAffectAll
      Exit Sub
    UpdateErr:
      MsgBox Err.Description
    End Sub
    So is it REALLY opened????
    Firstly using bound controls is evil.

    Secondly, batch updates are provider specific. The provider you use to open your connection determines if a batch update is possible.

    Thirdly, I don't remember if the adodc control supports a batch update, but I am going to look that up.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  5. #5

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Updateing Access Database

    Ok....re-did it using un-bound controls.
    Code:
    Option Explicit
    Private cn As ADODB.Connection  'this is the connection object
    Private rs As ADODB.Recordset   'this is the recordset object
    
    Private Sub Form_Load()
        'instantiate the connection object
        Set cn = New ADODB.Connection
        'specify the connectionstring
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                              "Data Source=" & App.Path & "\Database\csv1000.mdb"
        'open the connection
        cn.Open
        
        'instantiate the recordset object
        Set rs = New ADODB.Recordset
        'open the recordset
        With rs
            .Open "csv1000_table", cn, adOpenKeyset, adLockPessimistic, adCmdTable
               
            'loop through the records until reaching the end or last record
            Do While Not .EOF
              tester_first_name.Text = rs.Fields("TESTER_FIRST_NAME")
                rs.MoveNext 'moves next record
            Loop
            
            If Not (.EOF And .BOF) Then
                rs.MoveFirst    'go to the first record if there are existing records
                FillFields      'to reflect the current record in the controls
            End If
            
        End With
    End Sub
    ....filling fields with using:
    Code:
    tester_first_name.Text = rs.Fields("TESTER_FIRST_NAME")
    ...and updating DB using:
    Code:
    rs.Fields("TESTER_FIRST_NAME") = tester_first_name.Text
    rs.Update 'this updates the recordset
    Now....my problem is doing the update from another form. I tried this:
    Code:
    Patient_Info3.rs.Update 'this updates the recordset
    but it tells me "Method or Data Member not found" What is the proper way to save/update from another form???

    Thanks for all the help.....this is the best VB forum around!!!
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

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

    Re: Updateing Access Database

    You are getting that error because rs is declared using the keyword Private, if you change that to Public it should get past that error. For more info see the article What is the difference between Dim/Private/Public/Global/Static/Const? from our Classic VB FAQs (in the FAQ forum)

    However, if you are just using that line it will not make any changes to the fields, so wont seem to update anything. It may be best to simulate a click of your command button instead, eg:
    Code:
    Patient_Info2.cmdUpdate.value = True

  7. #7

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Updateing Access Database

    The changes to the fields have already occurred elsewhere on the form, I just need to update/save the record. So should I use:
    Code:
    Patient_Info2.cmdUpdate.value = True
    or
    Code:
    Patient_Info3.rs.Update
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  8. #8
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Updating Access Database

    Quote Originally Posted by si_the_geek View Post
    You are getting that error because rs is declared using the keyword Private, if you change that to Public it should get past that error. For more info see the article What is the difference between Dim/Private/Public/Global/Static/Const? from our Classic VB FAQs (in the FAQ forum)

    However, if you are just using that line it will not make any changes to the fields, so wont seem to update anything. It may be best to simulate a click of your command button instead, eg:
    Code:
    Patient_Info2.cmdUpdate.value = True
    Quote Originally Posted by aa9gg View Post
    The changes to the fields have already occurred elsewhere on the form, I just need to update/save the record. So should I use:
    Code:
    Patient_Info2.cmdUpdate.value = True
    or
    Code:
    Patient_Info3.rs.Update
    Did you read si's post? This happened due to the scope of your variable. You could use
    Code:
    Patient_Info3.rs.Update
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  9. #9

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Updateing Access Database

    Yes...I did. Just wondering which is the better method (after I change the scope of my var.)
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

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

    Re: Updateing Access Database

    Quote Originally Posted by aa9gg View Post
    The changes to the fields have already occurred elsewhere on the form,
    Have the changes been written to the recordset? (eg: rs.Fields("TESTER_FIRST_NAME") = tester_first_name.Text )

    If they have then Patient_Info3.rs.Update by itself is fine.

    Otherwise you need to write the changes to the recordset - which I presume is what cmdUpdate does, so calling that is the simplest solution.

  11. #11

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Updateing Access Database

    Hi Si...
    Yes they have. Works great...thanks again!
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

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