aziz rasul
Active member
- Local time
- Today, 16:49
- Joined
- Jun 26, 2000
- Messages
- 1,935
I have the following piece of code.
Set rstRecon = dbs.OpenRecordset("tblReconciliation")
record_count = DCount("ID", "tblReconciliation")
With rstRecon
.MoveFirst
x = 1
Do While rstRecon("Period") <> Me!Period And rstRecon("Year") <> Me!Year
.MoveNext
x = x + 1
If x > record_count Then
.AddNew
!Period = Me!Period
!Year = Me!Year
.Update
End If
Loop
What the code is supposed to do is to look at the values of Me!Period (typically 1, 2, 3, ... 12) and Me!Year (typically 2001-02, 2002-03, etc.) and check whether there is a record in tblReconciliation. If not it should create a new record.
The problem is that the Do While statement only looks at the
rstRecon("Period") <> Me!Period
and not the whole statement i.e.
rstRecon("Period") <> Me!Period And rstRecon("Year") <> Me!Year
How do I change the code so that it checks the above without having to use 2 Do Loop statements?
Set rstRecon = dbs.OpenRecordset("tblReconciliation")
record_count = DCount("ID", "tblReconciliation")
With rstRecon
.MoveFirst
x = 1
Do While rstRecon("Period") <> Me!Period And rstRecon("Year") <> Me!Year
.MoveNext
x = x + 1
If x > record_count Then
.AddNew
!Period = Me!Period
!Year = Me!Year
.Update
End If
Loop
What the code is supposed to do is to look at the values of Me!Period (typically 1, 2, 3, ... 12) and Me!Year (typically 2001-02, 2002-03, etc.) and check whether there is a record in tblReconciliation. If not it should create a new record.
The problem is that the Do While statement only looks at the
rstRecon("Period") <> Me!Period
and not the whole statement i.e.
rstRecon("Period") <> Me!Period And rstRecon("Year") <> Me!Year
How do I change the code so that it checks the above without having to use 2 Do Loop statements?