MY OLD CODE DOESN'T WORK

skollager

New member
Local time
Today, 23:48
Joined
Apr 20, 2001
Messages
5
A while ago i developed a little program that lets users remove items of stock from store.(access 2.0).

Years later we upgraded to access97 the code no longer worked?

Can anybody shed any light on this. I have entered the code below in full. I have since changed the code but it doesn't work as whell as this code did. any suggestion would be of great help as we have in the last few months upgraded to access 2000.

Private Sub Part_Number_AfterUpdate()
Dim D As Database, C As Control, R As Recordset
Set D = DBEngine.Workspaces(0).Databases(0)
Set C = Screen.ActiveControl
Set R = D.OpenRecordset(C.RowSource)
R.FindFirst "[Part Number]=" & C
[Part] = R![Part]
[Total] = R![Price]
[Total] = [Quantity] * [Total]
If [Quantity] > R![Quantity] Then
MsgBox "You cannot book out more than the actual amount in the store!", vbOKOnly, "McCarthy & Sons Ltd"
DoCmd.GoToControl "Quantity"
[Quantity] = 0
[Part Number] = Null
[Net] = 0
Else: MsgBox "Remove " & Quantity & " " & [Part] & " From Store?", vbOKCancel, "Remove Item"
If VbMsgBoxResult.vbCancel Then
DoCmd.GoToControl "Quantity"
[Quantity] = 0
[Part Number] = Null
[Net] = 0
If VbMsgBoxResult.vbOK Then
R.Edit
R!Quantity = R!Quantity - [Quantity]
R.Update
End If
End If
End If
End Sub
 
I have some questions:
1) Does the form module contain "Option explicit" ?
2)Does this code compile properly?

At first glance I can give you the following hints:

1) This is not generic code, thus it is senseless to use Screen.activecontrol.
2) SIMPLIFY your code
3) use the debugger to step through the code (after simplification)
4) close the objects
 

Users who are viewing this thread

Back
Top Bottom