hi i am a beginner in VBA.
i have a double loop where the loop check if a number is higher then 200. but it seams like when the loop ends, and it does`nt take the value up to the start of the loop.
can anybody help me?
my task is to select values from a recordset, and then insert it in another recordset. but the values inserted in the new recordset cant exceed over the value 200. if there are values over 200 in the first recordset, then the loop is gonna subtact 200 each time.
CODE:
Private Sub comBeregn_Click()
Dim strsql As String
Dim stdset As DAO.Recordset
Dim nLength As Long
strsql = "SELECT * FROM 1strecordset"
Set stdset = CurrentDb.OpenRecordset(strsql)
stdset.movelast
stdset.movefirst
With stdset
Do While Not .EOF
nLenght = 0
if !recordset1value >= 0 Then
nLenght = !recordset1value
End If
If nLength > 200 Then
nLength = nLength - 200
end if
strsql = "INSERT INTO Recordset2 (recordset2value) VALUES (" & nLength & ")"
CurrentDb.Execute (strsql),dbfailonerror
.MoveNext
Loop
.Close
set stdset = nothing
End With
end sub
i have a double loop where the loop check if a number is higher then 200. but it seams like when the loop ends, and it does`nt take the value up to the start of the loop.
can anybody help me?
my task is to select values from a recordset, and then insert it in another recordset. but the values inserted in the new recordset cant exceed over the value 200. if there are values over 200 in the first recordset, then the loop is gonna subtact 200 each time.
CODE:
Private Sub comBeregn_Click()
Dim strsql As String
Dim stdset As DAO.Recordset
Dim nLength As Long
strsql = "SELECT * FROM 1strecordset"
Set stdset = CurrentDb.OpenRecordset(strsql)
stdset.movelast
stdset.movefirst
With stdset
Do While Not .EOF
nLenght = 0
if !recordset1value >= 0 Then
nLenght = !recordset1value
End If
If nLength > 200 Then
nLength = nLength - 200
end if
strsql = "INSERT INTO Recordset2 (recordset2value) VALUES (" & nLength & ")"
CurrentDb.Execute (strsql),dbfailonerror
.MoveNext
Loop
.Close
set stdset = nothing
End With
end sub