B
Beth
I have recently discovered HasData thanks to this site
and find it handy to prevent opening a form that is
called via a command button on a MAIN form.
When my MAIN form is bound all is good with my world. Now
I am trying to do the same with an unbound MAIN form. The
error is "variable not defined". My code seems correct,
so I infer that the problem is the unbound form. This
unbound form is merely a holder for many buttons to open
other forms and reports. Am I correct and what do I do
about it?
My code is below. Any MVP like to help me out with this?
I am not a professional, nor do I play one on TV.
Thanks,
Beth
*****************************************************
(this code is attached to the OnClick of a command button)
If HasData(CLid) Then
Dim stDocName As String
stDocName = "frmCL"
DoCmd.OpenForm stDocName
Else
MsgBox "There is no data."
End If
****************************************************
Function HasData(CLid) As Boolean
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim SQL As String
Set db = CurrentDb()
SQL = "SELECT [qryCL].CLid FROM [qryCL] WHERE [CLid] ='"
& [CLid] & "';"
Set rst = db.OpenRecordset(SQL)
If rst.EOF And rst.BOF Then
HasData = False
Else
HasData = True
End If
End Function
****************************************************
and find it handy to prevent opening a form that is
called via a command button on a MAIN form.
When my MAIN form is bound all is good with my world. Now
I am trying to do the same with an unbound MAIN form. The
error is "variable not defined". My code seems correct,
so I infer that the problem is the unbound form. This
unbound form is merely a holder for many buttons to open
other forms and reports. Am I correct and what do I do
about it?
My code is below. Any MVP like to help me out with this?
I am not a professional, nor do I play one on TV.
Thanks,
Beth
*****************************************************
(this code is attached to the OnClick of a command button)
If HasData(CLid) Then
Dim stDocName As String
stDocName = "frmCL"
DoCmd.OpenForm stDocName
Else
MsgBox "There is no data."
End If
****************************************************
Function HasData(CLid) As Boolean
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim SQL As String
Set db = CurrentDb()
SQL = "SELECT [qryCL].CLid FROM [qryCL] WHERE [CLid] ='"
& [CLid] & "';"
Set rst = db.OpenRecordset(SQL)
If rst.EOF And rst.BOF Then
HasData = False
Else
HasData = True
End If
End Function
****************************************************