Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset Problem for "Mass Update"

Status
Not open for further replies.

jmcbay

Programmer
Feb 24, 2002
4
US
I'm trying to create a form that will allow the user to "mass update" multiple customers at the same time. The customers are listed as a list box and the user can multiple select. There are 13 fields on the form that the user can edit and I want any edited fields to be changed on all the selected customers, but if a field is not edited I want the field to stay the same.

It may be a problem just because I don't understand recordsets (any explanations are welcome!) or that I've designed it wrong, but I'm having problems in the following areas:
(1) with records being locked from a previous edit,
(2) the first record being changed, but the second one not changed at all (it leaves an orphan in the table)
(3) how can I leave the field alone when the one on the form is not changed
(4) how can I most efficiently check all 13 fields?

I'm inserting my code for anyone who will help!!

Thanks,
Jackie

Code:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

Dim CurrentRow As Integer
Dim ctlSource As Control
Dim CustID As Integer
Dim myRS As Recordset
Dim myDB As Database
Dim strSQL As String

Set myDB = CurrentDb
Set ctlSource = Me!CustList
Set myRS = myDB.OpenRecordset("tTripCustomer")

     For intCurrentRow = 1 To ctlSource.ListCount - 1
        If ctlSource.Selected(intCurrentRow) Then
            CustID = ctlSource.Column(0, intCurrentRow)
            If myRS.RecordCount > 0 Then
                  ' myRS.LockEdits = True
                   myRS.FindFirst ("[tcCID]=" & CustID)
                   If Not myRS.NoMatch Then
                        If IsNull(Me!tcAmtDue) = False Then
                        myRS.Edit
                        myRS("tcCID").Value = CustID
                        myRS("tcAmtDue").Value = Me!tcAmtDue
                        If IsNull(Me!tcPytMethod) = False Then
                            myRS("tcPytMethod").Value = Me!tcPytMethod
                        End If
                        myRS.Update
                        'myRS.LockEdits = False
                   End If
                End If
            End If
        End If
    Next intCurrentRow
    myRS.Close
    myDB.Close
        
    DoCmd.Close

Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    MsgBox Err.Description
    
    Resume Exit_cmdClose_Click
    
End Sub
 
The natural order in Access would be to have the select list on the first form, then select the customers, then build a query for the selected customers, then open a second form with just those customers and let the user update what they want. You shouldn't need to create a recordset in vba code to do this. Access is already setup to do what you want in a form by having the resultset you want available to a form.
 
It's adding another record into the table with the changes I made. What am I doing wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top