April15Hater
Accountant
- Local time
- Today, 12:00
- Joined
- Sep 12, 2008
- Messages
- 349
Hi Guys,
I'm have two listboxes: lstUnassigned and lstAssigned that (to quote LPurvis) "Assigns related records - selecting from 'Unassigned' listbox to 'Assigned' listbox entries."
The problem I'm having is when I click on one to go from unassigned to assigned, it moves it over to assigned, but it fails to take it away from the unassigned. Here's where it get's wierd. When I close and reopen the form, the listboxes requery, and it shows everything correctly. This sounds like the textbook example of leaving out me.objectname.requery, I know. The thing is I've checked my code a million times. In fact, I stepped through it twice just to be sure. I can't figure out for the life of me why this isn't updating properly. My next option is to just have it close and reopen the form everytime, but that's a really poor solution.
Any suggestions? Code posted below.
Thanks,
Joe
lstUnassigned:
lstassigned
Form VBA
I'm have two listboxes: lstUnassigned and lstAssigned that (to quote LPurvis) "Assigns related records - selecting from 'Unassigned' listbox to 'Assigned' listbox entries."
The problem I'm having is when I click on one to go from unassigned to assigned, it moves it over to assigned, but it fails to take it away from the unassigned. Here's where it get's wierd. When I close and reopen the form, the listboxes requery, and it shows everything correctly. This sounds like the textbook example of leaving out me.objectname.requery, I know. The thing is I've checked my code a million times. In fact, I stepped through it twice just to be sure. I can't figure out for the life of me why this isn't updating properly. My next option is to just have it close and reopen the form everytime, but that's a really poor solution.
Any suggestions? Code posted below.
Thanks,
Joe
lstUnassigned:
Code:
SELECT tblProductionTracking.ProductionTrackingID, tblProductionTracking.ProductionID, tblProductionTracking.FunctionTrackingID, tblProductionTracking.TrackingNumber
FROM tblProductionTracking
WHERE (((tblProductionTracking.ProductionID)<>[Forms]![frmProductionStep3b]![cboProductionID]) AND ((tblProductionTracking.FunctionTrackingID)=[Forms]![frmProductionStep3b]![cboFunctionTrack]) AND ((tblProductionTracking.TrackingNumber) Not In (SELECT tblProductionTracking.TrackingNumber FROM tblProductionTracking WHERE (((tblProductionTracking.ProductionID)<>[forms]![frmProductionStep3b]![txtProductionID]) AND ((tblProductionTracking.FunctionTrackingID)=[forms]![frmProductionStep3b]![cboFunctionTrack])))));
Code:
SELECT tblProductionTracking.TrackingNumber, tblProductionTracking.ProductionTrackingID, tblProductionTracking.ProductionID, tblProductionTracking.FunctionTrackingID
FROM tblProductionTracking
WHERE (((tblProductionTracking.ProductionID)=[forms]![frmProductionStep3b]![txtProductionID]) AND ((tblProductionTracking.FunctionTrackingID)=[forms]![frmProductionStep3b]![cboFunctionTrack]));
Code:
Private Sub lstAssigned_DblClick(Cancel As Integer)
Dim rsListBox As ADODB.Recordset
Set rsListBox = New ADODB.Recordset
With rsListBox
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT * FROM tblProductionTracking WHERE ProductionTrackingID = " & Me.lstAssigned.Column(1)
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open
.Delete
.Update
.Close
End With
Me.lstUnassigned.Requery
Me.lstAssigned.Requery
End Sub
Private Sub lstUnassigned_DblClick(Cancel As Integer)
Dim rsListBox As ADODB.Recordset
Set rsListBox = New ADODB.Recordset
With rsListBox
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT * FROM tblProductionTracking"
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open
.AddNew
!ProductionID = Me.txtProductionID.Value
!FunctionTrackingID = Me.cboFunctionTrack.Value
!TrackingNumber = Me.lstUnassigned.Column(3)
.Update
.Close
End With
Me.lstAssigned.Requery
Me.lstUnassigned.Requery
End Sub