Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test For Null in SubForm via VBA 1

Status
Not open for further replies.

Cleis

Technical User
Jun 4, 2000
197
US
Hi Group:

I know their is an easy answer to this but I can't seem to figure this out.

Main Form Name = "frmPostVoucher
Sub Form Name = "frmPostVoucherSubPrint"

**I want to test if there are no records or null
**I can sucessfully test if there is more than 1 record
**I have tried the following:
** Forms![frmPostVoucher]![frmPostVoucherSubPrint].Form![txtPrintCount] = Null
** IsNull(Forms![frmPostVoucher]![frmPostVoucherSubPrint].Form![txtPrintCount])

See below

Private Sub CmdClose_Click()
On Error GoTo Err_CmdClose_Click

If ckPrint = 0 And Forms![frmPostVoucher]![frmPostVoucherSubPrint].Form![txtPrintCount] = Null Then

DoCmd.Close

ElseIf ckPrint = 0 And Forms![frmPostVoucher]![frmPostVoucherSubPrint].Form![txtPrintCount] >= 1 Then

MsgBox "You cannot exit until you print off the Voucher and or deselect the records for printing.", vbExclamation, "Program Accounting"
Exit Sub

End If

Exit_CmdClose_Click:
Exit Sub

Err_CmdClose_Click:
MsgBox Err.Description
Resume Exit_CmdClose_Click

End Sub
 
Maybe:

[tt]If Me.RecordSource <> "" Then
If Me.Recordset.RecordCount = 0 Then
strRecError = "No Records. "
End If
Else
strRecError = "No recordset. "
End If[/tt]
 
Thanks tried it and got the ususual Object doesn't support this property or method.

I know this has a simple answer . . . sigh
 
Can you post the code as modified to suit your application, please?
 
Okay I wasted an afternoon on this! Ya' gotta' love DCounts! They are just like duck tape and work just as well!!

LOL!! Remou I did try several iterations of your suggestion. I just could'nt get the thing to work!! Maybe I'll come back to this when I've got a clearer head. For now a Field on the Main form using a Dcount does the same thing (not a nice as I would liked)!

Kind Regards and thanks for you input on a Sunday Afternoon!


Itch
 
Just as a note, to use on main form:
[tt]If Me.[frmPostVoucherSubPrint].Form.RecordSource <> "" Then
If Me.[frmPostVoucherSubPrint].Form.Recordset.RecordCount = 0 Then
strRecError = "No Records. "
End If
Else
strRecError = "No recordset. "
End If[/tt]
 
A little food and a clear mind! Your code worked!!! I was missing the bold . . . duh

Me.[frmPostVoucherSubPrint] .Form .RecordSource <> "" Then . . .

Many Many thanks! Here is a star for ya'!


Regards!

Itch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top