Results 1 to 6 of 6
  1. #1
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25

    Help With Save Data Code

    Hi,
    I have a table named tbWONumber and a form named frViewWorkOrder.
    On the form 2 command buttons 1, coListWorkOrders which makes a list box visible to select a work order and 2, coSaveWO which is supposed to save any updates to boxes on the form.
    The list box works ok and populates the correct fields on the form.
    However, I cannot get the save button to update the table with any changes made to fields on the form.
    Any help would be very much appreciated.
    -------------------------------------------
    Private Sub coListWorkOrders_Click()

    Me.lbWorkOrders.Visible = True

    End Sub
    --------------------------------------------
    Private Sub lbWorkOrders_Click()

    Me.txWONumber = lbWorkOrders.Column(0)
    Me.txReceivedBy = lbWorkOrders.Column(11)
    Me.txWODate = lbWorkOrders.Column(4)
    Me.cbEquipID = lbWorkOrders.Column(1)
    Me.txEquipDesc = lbWorkOrders.Column(2)
    Me.txEquipLoc = lbWorkOrders.Column(3)
    Me.txFirstName = lbWorkOrders.Column(5)
    Me.txLastName = lbWorkOrders.Column(7)
    Me.txPosition = lbWorkOrders.Column(8)
    Me.txDatePromised = lbWorkOrders.Column(10)
    Me.cbPriority = lbWorkOrders.Column(16)
    Me.txProblemDescription = lbWorkOrders.Column(6)
    Me.txWorkDone = lbWorkOrders.Column(9)
    Me.txLaborHours = lbWorkOrders.Column(12)
    Me.txActualCost = lbWorkOrders.Column(13)
    Me.txDateCompleted = lbWorkOrders.Column(14)
    Me.txWOClosed = lbWorkOrders.Column(15)
    Me.cbClassification = lbWorkOrders.Column(17)
    Me.cbEmployeeID = lbWorkOrders.Column(18)
    Me.txReceivedBy.SetFocus
    Me.lbWorkOrders.Visible = False

    End Sub
    -----------------------------------------------------------------
    Private Sub coSaveWO_Click()
    On Error GoTo Err_coSaveWO_Click
    Me.txReceivedBy.SetFocus

    If DCount("WONumber", "tbWorkOrder", "[WONumber] = '" & Me.txWONumber & "'") > 0 Then
    MyMsg = MsgBox("Updating Data Only, Work Order Number Remains The Same!", vbOKCancel, "Update Work Order")
    If MyMsg = 1 Then
    [tbWorkOrder.WONumber] = txWONumber
    [tbWorkOrder.EqID] = cbEquipID
    [tbWorkOrder.EqDescription] = txEquipDesc
    [tbWorkOrder.EqLocation] = txEquipLoc
    [tbWorkOrder.WODate] = txWODate
    [tbWorkOrder.EmployeeID] = cbEmployeeID
    [tbWorkOrder.EmpFirstName] = txFirstName
    [tbWorkOrder.EmpLastName] = txLastName
    [tbWorkOrder.EmpPosition] = txPosition
    [tbWorkOrder.ProblemDescription] = txProblemDescription
    [tbWorkOrder.WorkDone] = txWorkDone
    [tbWorkOrder.DatePromised] = txDatePromised
    [tbWorkOrder.ReceivedBy] = txReceivedBy
    [tbWorkOrder.LaborHours] = txLaborHours
    [tbWorkOrder.ActualCost] = txActualCost
    [tbWorkOrder.DateCompleted] = txDateCompleted
    [tbWorkOrder.WOClosed] = txWOClosed
    [tbWorkOrder.WOPriority] = cbPriority
    [tbWorkOrder.WOClassification] = cbClassification
    Me.Refresh
    DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
    Else
    Exit Sub
    End If

    Else
    Exit Sub
    End If



    Exit_coSaveWO_Click:
    Exit Sub

    Err_coSaveWO_Click:
    MsgBox Err.Description
    Resume Exit_coSaveWO_Click

    End Sub

  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,641
    The simplest solution would simply be to have the form bound to the table. That makes pretty much everything automatic. To do it how you are, you'll either need to open a recordset on the target table or execute an update query. You can't simply refer to the table like that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25
    The form is bound to the table tbWorkOrder. Have tried recordset but can't seem to get that way to work either.
    Trying to get the record to update has been driving me around the bend for the last week.
    Message usually is can't update as will cause duplicate entry

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    If the form is bound to the table, and the textboxes are bound to their respective fields, you shouldn't need all that code. Try the combo or list box wizard and choose the option to "Find a record...". That will bring up the chosen record, and any changes to the record should save automatically.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25
    Thanks Paul, am learning about Access as I go. Think I was trying to make it more complicated than needed. Have made new form and bound all to the table. Drop down list box to select record which can new be edited and saved via a command button.
    All looking good - thanks very much.
    Colin

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No problem Colin. Good luck on the project and post again if you get stuck.
    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. Report changes will not save
    By phyllisgirl in forum Reports
    Replies: 4
    Last Post: 05-07-2012, 09:28 PM
  2. Save to PDF Button?
    By SpeedyApocalypse in forum Forms
    Replies: 2
    Last Post: 04-10-2010, 06:06 PM
  3. Replies: 4
    Last Post: 04-01-2009, 11:48 AM
  4. Find data, load data, and save as a new record
    By hawzmolly in forum Access
    Replies: 0
    Last Post: 10-05-2008, 03:18 PM
  5. Save only 3 of 4 fields
    By Schwagr in forum Forms
    Replies: 0
    Last Post: 03-24-2006, 05:20 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