newaccess user
Registered User.
- Local time
- Today, 04:23
- Joined
- Oct 31, 2012
- Messages
- 27
Hello,
I have VBA code for a Print Preview button on the main form that previews the current record in a separate Report using this code:
I use this Print Preview code on a Button in the Form Header. The Main form lists head of household information. I also have a tabbed control with three tabs that have SubForms for Address, Children and Contact details.
The problem I have is that if any of the subforms are left blank I get a Run-Time Error '3021': No Current Record. If I Debug (press the button), it takes me straight to this line:
highlighted in Yellow.
Anyone on my database must have an address, should have contact details and could have children. If any one of these is blank then the print preview will not work.
I would like to know how to stop this error happening for blank records in my subforms.
I am a complete novice BTW and I would appreciate any help you may be able to provide.
Thanks in Advance.
I have VBA code for a Print Preview button on the main form that previews the current record in a separate Report using this code:
Code:
Private Sub cmdPrintRecord_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID_Soldier] = " & Me.[ID_Soldier]
DoCmd.OpenReport "rptRecordPrint", acViewPreview, , strWhere
End If
End Sub
I use this Print Preview code on a Button in the Form Header. The Main form lists head of household information. I also have a tabbed control with three tabs that have SubForms for Address, Children and Contact details.
The problem I have is that if any of the subforms are left blank I get a Run-Time Error '3021': No Current Record. If I Debug (press the button), it takes me straight to this line:
Code:
varAge = DateDiff("yyyy", varBirthDate, Now)
Anyone on my database must have an address, should have contact details and could have children. If any one of these is blank then the print preview will not work.
I would like to know how to stop this error happening for blank records in my subforms.
I am a complete novice BTW and I would appreciate any help you may be able to provide.
Thanks in Advance.