Link to home
Start Free TrialLog in
Avatar of iainmacleod
iainmacleodFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Use of variant in Do

I have the following code that seems to work sometimes but not all of the time. If I replace the variant "Cstock" with a number then the number stores down in the table. But the variant does not. Please help

Dim Cdb As DAO.Database, sd As DAO.Recordset, ps As DAO.Recordset, strMsg As String, iResponse As Integer, cstock As Variant

Set Cdb = CurrentDb
Set sd = Cdb.OpenRecordset("stockdetails", dbOpenDynaset)
Set ps = Cdb.OpenRecordset("purchasedstock", dbOpenDynaset)

sd.MoveFirst
Do While Not sd.EOF
    If sd!sid = Me.stockid Then
    sd.Edit
    cstock = (Me.quantity + sd!stocktotal)
    sd!stocktotal = cstock
   
   
    sd.Update
    Forms!stockdetailalterview.stocktotal = sd!stocktotal
    Forms!stockdetailalterview.availablestock = sd!stocktotal - sd!stockringfenced

    Forms!stockdetailalterview.Refresh
    'DoCmd.Close
    Exit Do
    Else
    sd.MoveNext
    End If
Loop
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iainmacleod

ASKER

Thats fantastic, works a treat. Many thanks