Prevent opening of a form without no data (1 Viewer)

sanalsurabhi

New member
Local time
Tomorrow, 02:48
Joined
Jan 14, 2010
Messages
7
How to prevent opening of a form which has no data and display a message in this regard in access 2007.
 

Ranman256

Well-known member
Local time
Today, 17:18
Joined
Apr 9, 2015
Messages
4,337
in the query that the form uses , ie: qsData
check to see if it has records:

Code:
sub btnOpenFrm_click()
if Dcount("*","qsData")>0 then 
    docmd.OpenForm "fMyForm"
else
    msgbox "No data"
endif

end sub
 

sanalsurabhi

New member
Local time
Tomorrow, 02:48
Joined
Jan 14, 2010
Messages
7
Thank you for the reply. My query has data but no data in respect of a particular "EmpID". I am trying to change your code to suit the situation. Can you help me?
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:18
Joined
Sep 21, 2011
Messages
14,432
How are you passing the EmpID to the form?
 

missinglinq

AWF VIP
Local time
Today, 17:18
Joined
Jun 20, 2003
Messages
6,423
If EmpID is Numeric

Code:
If DCount("*", "YourQueryName", "EmpID =" & Me.EmpID) > 0 Then

  DoCmd.OpenForm "FormName", , , "EmpID =" & Me.EmpID

Else

  MsgBox "No Matching Record Found!"

End If

If EmpID is Text

Code:
If DCount("*", "YourQueryName", "EmpID ='" & Me.EmpID & "'") > 0 Then

  DoCmd.OpenForm "FormName", , , "EmpID ='" & Me.EmpID & "'"

Else

  MsgBox "No Matching Record Found!"

End If
Linq ;0)>
 

Users who are viewing this thread

Top Bottom