- Apr 20, 2010
- 4,464
- 6
- 81
In my app, users are selecting records from a listbox that they want to edit. Before they're able to edit, however, there is an additional query to make sure that info they want to change is correct. Below is the flow:
I'm wondering if there is a way to ensure that the selected records stay selected, or if there is a way to store which rows were selected so they can be referenced again after the requery code is ran?
Entirety of the code. It may look slightly confusing because I don't have anything noted with "Me."
I'll provide any additional info I can to assist you in assisting me further.
- User inputs an Item_Number and clicks a button to query the DB for all Location(s) that contain that Item_Number. These populate into a listbox.
- User selects the location(s) from the listbox that he/she wishes to edit
- User inputs a new Last_Cost and/or new Vendor_ID for the selected items and clicks to confirm edit
- In VBA, there is a query against another DB to ensure the new Vendor_ID is valid
- The flow continues
I'm wondering if there is a way to ensure that the selected records stay selected, or if there is a way to store which rows were selected so they can be referenced again after the requery code is ran?
Entirety of the code. It may look slightly confusing because I don't have anything noted with "Me."
Code:
Private Sub EditInLocationsButton_Click()
EditVendorIDFixed = Null
EditVendorIDFixed = " " & EditVendorIDInput
DoCmd.Requery (VendorNumbers)
If EditVendorIDFixed = " " Or DCount("*", "VendorNumbers") > 0 Then
EditResponse = MsgBox("Are you sure you want to edit the selected items?", vbYesNo, "Edit Selected Items?")
If EditResponse = vbYes Then
'EditItemNumberResultsList.RowSource = ""
Dim i As Integer
For i = 0 To EditItemNumberResultsList.ListCount - 1
If EditItemNumberResultsList.Selected(i) Then
LastCost = EditItemNumberResultsList.Column(4, i)
EditID = EditItemNumberResultsList.Column(5, i)
VendorID = EditItemNumberResultsList.Column(6, i)
'MsgBox for verification purposes
MsgBox (LastCost & "-" & EditID & "-" & VendorID)
If EditLastCostInput = Null Then
LastCostforEditQuery = LastCost
Else
LastCostforEditQuery = EditLastCostInput
End If
If EditVendorIDInput = Null Then
VendorIDforEditQuery = VendorID
Else
VendorIDforEditQuery = EditVendorIDFixed
End If
End If
txtEditID = EditID
With DoCmd
.SetWarnings False
.OpenQuery "EditIminvlocRecords"
.SetWarnings True
End With
Next i
MsgBox ("The selected plants have been updated.")
End If
Else
MsgBox ("Error: The requested Vendor ID does not exist.")
End If
End Sub
I'll provide any additional info I can to assist you in assisting me further.