Hi All,
I’m little lost in my loop try records , so if someone can help me with this.
In subform I have 5 fields , on first four user enter data immediately but last one thay enter after one week or what ever. On subform is Add button and onclick event is this code :
Private Sub btnAdd_Click()
On Error GoTo Err_btnAdd_Click
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Table1.SendDate FROM [Table1] WHERE Table1.MainID = " & Forms!TestAllFields.MainID)
rst.MoveFirst
Do Until rst.EOF
If IsNull(rst!SendDate) Then
MsgBox " 'Send To Acc' date is empty. Please enter date first!"
Me.AllowAdditions = False
Else
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Exit_btnAdd_Click:
Exit Sub
Err_btnAdd_Click:
MsgBox Err.Number & Chr$(13) & Err.Description
Resume Exit_btnAdd_Click
End Sub
So code is working if in subform some record exist, but if in subform is no records and if I click on add button I get error : 3021 No Current record.
So I was try with : if err. Number = 3021 then Resume Next…. But now nothing happand ( no error and no new record L )
In this scenario I have two tables :
Main have two fields : MainID(PK) and one text field.
Table for subform : TestID(PK) , MainID(FK), Sum, Currency, Amount, SendDate .
Thanks
Fule
I’m little lost in my loop try records , so if someone can help me with this.
In subform I have 5 fields , on first four user enter data immediately but last one thay enter after one week or what ever. On subform is Add button and onclick event is this code :
Private Sub btnAdd_Click()
On Error GoTo Err_btnAdd_Click
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Table1.SendDate FROM [Table1] WHERE Table1.MainID = " & Forms!TestAllFields.MainID)
rst.MoveFirst
Do Until rst.EOF
If IsNull(rst!SendDate) Then
MsgBox " 'Send To Acc' date is empty. Please enter date first!"
Me.AllowAdditions = False
Else
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Exit_btnAdd_Click:
Exit Sub
Err_btnAdd_Click:
MsgBox Err.Number & Chr$(13) & Err.Description
Resume Exit_btnAdd_Click
End Sub
So code is working if in subform some record exist, but if in subform is no records and if I click on add button I get error : 3021 No Current record.
So I was try with : if err. Number = 3021 then Resume Next…. But now nothing happand ( no error and no new record L )
In this scenario I have two tables :
Main have two fields : MainID(PK) and one text field.
Table for subform : TestID(PK) , MainID(FK), Sum, Currency, Amount, SendDate .
Thanks
Fule