Results 1 to 2 of 2
  1. #1
    ismith is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    39

    Need help editing Database via Form

    Hello,

    Ive got a form with bound txt boxes that displays the information in the database. Now ive put an edit button which when its clicked it allow the txt boxes and combo boxes to be edited.

    Ive got the edits and so forth to work.

    This is the coding for my Save Button



    Code:
     
    Private Sub btnSave_Click()
    If Trim("" & Description.Value) = "" Then
    MsgBox "Please enter a Description", vbExclamation, "Cannot Save"
    ElseIf Trim("" & Category.Value) = "" Then
    MsgBox "Please select a Category", vbExclamation, "Cannot Save"
    ElseIf Trim("" & Quantity.Value) = "" Then
    MsgBox "Please enter a Quantity", vbExclamation, "Cannot Save"
    ElseIf Not IsNumeric(Quantity.Value) Then
    MsgBox "Quantity can only contain numbers", vbExclamation, "Cannot Save"
    ElseIf Quantity.Value = 0 Then
    MsgBox "The quantity must be over Zero", vbExclamation, "Cannot Save"
    ElseIf Quantity.Value < 0 Then
    MsgBox "The quantity must be over Zero", vbExclamation, "Cannot Save"
    ElseIf Price.Value = 0 Then
    MsgBox "The price must be over Zero", vbExclamation, "Cannot Save"
    ElseIf Price.Value < 0 Then
    MsgBox "The price must be over Zero", vbExclamation, "Cannot Save"
    ElseIf Trim("" & Price.Value) = "" Then
    MsgBox "Please enter a Price", vbExclamation, "Cannot Save"
    ElseIf MsgBox("Edit Product Details?", vbOKCancel + vbQuestion, "Confirmation") = vbOK Then
    'get a reference to the record set in the main form
    
    Set dbs = CurrentDb
    Set editprod = dbs.OpenRecordset("tblProduct")
    
    editprod.Edit
    
    editprod("[Description]") = Description.Value
    editprod("[Category]") = Category.Value
    editprod("[Size]") = Size.Value
    editprod("[Quantity]") = Quantity.Value
    editprod("[Price]") = "£" + Price.Value
    
    editprod.Update
    
    MsgBox ("Updated")
    End If
    Exit Sub
    End Sub




    Now that code does add to the product table but it dont change that specific Record. It just overwrites the information in the 1st Record.
    And if i edit another record, the 1st Record in the database gets overwritten again.




    Any ideas how i can stop this and change the values of the product i have chosen?


    Each product does have a Uniwue ProductID but i cant get it to change the Record that is chosen.


    All help is welcome..



    Thanks..

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    I know you have this elsewhere, so I'll be brief. If the textboxes are bound to the underlying table, why do you need code? If they're not (which would be simplest), you need to open the correct record:

    Set editprod = dbs.OpenRecordset("SELECT * FROM tblProduct WHERE ProductID = " & Me.ProductID)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Editing in Form Controls
    By waqas in forum Forms
    Replies: 3
    Last Post: 09-16-2011, 02:36 PM
  2. Editing Primary Key in Split Database
    By jaypoppin in forum Access
    Replies: 10
    Last Post: 03-16-2011, 10:39 AM
  3. Form for editing data
    By parad1se in forum Forms
    Replies: 1
    Last Post: 01-23-2011, 10:36 AM
  4. Replies: 2
    Last Post: 04-12-2010, 01:03 PM
  5. Form for Editing Only
    By Schwagr in forum Forms
    Replies: 4
    Last Post: 03-24-2006, 05:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums