Results 1 to 12 of 12

Thread: [RESOLVED] Update record not working

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] Update record not working

    I have the following code which, when I debug.print the strSQL, I get the updated data.
    The problem is, it doesn't save the changes and it doesn't thow an error, so I can't tell you what the error message could be.

    Can anybody see what is wrong with the code?
    Or could it be something wrong with the database set up, although there are plenty of records successfully saved into it!

    Thanks

    Code:
        Set cn = New ADODB.Connection
        cn.ConnectionString = strConnection & App.Path & "\Membership.mdb"
        cn.Open
        
        strSQL = "UPDATE tbl_Membership SET " & _
            "First_Name = '" & Replace(txtMembership(0).Text, "'", "''") & "', " & _
            "Middle_Name = '" & Replace(txtMembership(1).Text, "'", "''") & "', " & _
            "Surname = '" & Replace(txtMembership(2).Text, "'", "''") & "', " & _
            "Street = '" & Replace(txtMembership(3).Text, "'", "''") & "', " & _
            "Town = '" & Replace(txtMembership(4).Text, "'", "''") & "', " & _
            "City = '" & Replace(txtMembership(5).Text, "'", "''") & "', " & _
            "County = '" & Replace(txtMembership(6).Text, "'", "''") & "', " & _
            "Post_Code = '" & Replace(txtMembership(7).Text, "'", "''") & "', " & _
            "Home_Tel = '" & Replace(txtMembership(8).Text, "'", "''") & "', " & _
            "Mobile_Tel = '" & Replace(txtMembership(9).Text, "'", "''") & "', " & _
            "Email = '" & Replace(txtMembership(10).Text, "'", "''") & "', " & _
            "DOB = '" & Replace(txtMembership(11).Text, "'", "''") & "', " & _
            "Date_Joined = '" & Replace(txtMembership(12).Text, "'", "''") & "', " & _
            "Insurance_Due = '" & Replace(txtMembership(13).Text, "'", "''") & "', " & _
            "Grade = '" & Replace(txtMembership(14).Text, "'", "''") & "', " & _
            "Last_Graded = '" & Replace(txtMembership(15).Text, "'", "''") & "', " & _
            "Membership_Number = '" & Replace(txtMembership(16).Text, "'", "''") & "', " & _
            "Occupation = '" & Replace(txtMembership(17).Text, "'", "''") & "', " & _
            "Notes = '" & Replace(txtMembership(18).Text, "'", "''") & "' " & _
            "Where Memb_ID = " & lngSelection
                  
        cn.Execute strSQL
        cn.Close
        Set cn = Nothing
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Update record not working

    What is the value of "strConnection"
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Update record not working

    Quote Originally Posted by Mark Gambo
    What is the value of "strConnection"
    Sorry missed this reply!

    Code:
    Public Const strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "
    It's definately not this as it works every time i make a call to the database.

    Anything else jump out?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

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

    Re: Update record not working

    1) how do you *know* it's not saving the changes?
    2) I highly suggest you parameterize that query and use that instead. Many times a parameterized query is far easier to debug.
    3) display the SQL in a message box before running it... see if anything jumps out at you.
    4) Even though you thinkj you aren't getting errors, check the Errors Collection in the Connection object.... there might be something in there.

    -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??? *

  5. #5
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    396

    Re: Update record not working

    Hi aikidokid;

    Your query seems to be Ok. Have you checked...

    Code:
    "Where Memb_ID = " & lngSelection
    it's possible you are trying to update a non-existent record.

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Update record not working

    Have you tried looking at the value of strSQL before it is executed? output the value of strSQL into the immediate window and then copy and paste it into an Access Query and see if it updates. Can you post the value of strSQL?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Update record not working

    Quote Originally Posted by LinXG
    Hi aikidokid;

    Your query seems to be Ok. Have you checked...

    Code:
    "Where Memb_ID = " & lngSelection
    it's possible you are trying to update a non-existent record.

    Good point.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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

    Re: Update record not working

    If this Access... the query may still not be right.... DBO - is this a date field? I know it's stupposed to be a date going in, but is it stored as a date type field... or a string type field? If i'ts stored as a date, then dump the ' around it, and suround your date value with # instead:
    "DOB = #" & txtMembership(11).Text & "#, " & _


    -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??? *

  9. #9

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Update record not working

    Quote Originally Posted by LinXG
    Hi aikidokid;

    Your query seems to be Ok. Have you checked...

    Code:
    "Where Memb_ID = " & lngSelection
    it's possible you are trying to update a non-existent record.
    Thanks everybody who took the time to look at this for me.

    I have to admit that this was the problem.
    I have another variable with a very similar name (good lesson here).


    Quote Originally Posted by Mark Gambo
    Have you tried looking at the value of strSQL before it is executed? output the value of strSQL into the immediate window and then copy and paste it into an Access Query and see if it updates.
    Could you explain a bit more about how to use the Access Query and what to expect from it.

    A big thanks also to techgnome
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  10. #10
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Update record not working

    Quote Originally Posted by aikidokid
    . . .Could you explain a bit more about how to use the Access Query and what to expect from it.

    A big thanks also to techgnome
    Sure take a look at this graphic:
    Attached Images Attached Images  
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  11. #11

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Update record not working

    Thanks for this Mark, I will take a look

    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  12. #12
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Update record not working

    No problems, I am glad that I could help
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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