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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make a form not open when there is no data.

Status
Not open for further replies.

ruthcali

Programmer
Apr 27, 2000
470
US
this seems so easy, but it has stumped me all day!<br><br>i have a form where the user enters their name and password called frmName.&nbsp;&nbsp;then, they click ok and opens up another form i call frmSwitchboard.&nbsp;&nbsp;<br><br>the OnOpen event of the frmSwitchboard triggers another form to be opened that is based on a query.&nbsp;&nbsp;that form is called frmConstraint and the query it is based on is called qryConstraint.&nbsp;&nbsp;<br><br>sometimes the frmConstraint will contain data, sometimes it won't . all i want is for the form to open when there is data and to never open if it is empty.&nbsp;&nbsp;the tricky part is that the query qryConstraint has a parameter based on the name from frmName.<br><br>i have tried:<br><br>Dim db As Database<br>Dim rec As Recordset<br>Dim criteria As String<br><br>Set db = CurrentDb()<br>criteria = Chr(34) & Forms![frmName]![cboName] & Chr(34)<br>Set rec = db.OpenRecordset(&quot;qryConstraint&quot;)<br><br>&nbsp;DoCmd.OpenForm &quot;frmConstraint&quot;, , , &quot;[engineer]=&nbsp;&nbsp;&nbsp;&quot; & criteria & &quot;&nbsp;&nbsp;&quot;, acFormReadOnly, acDialog<br>rec.MoveLast<br>If rec.RecordCount &lt; 0 Then<br>&nbsp;DoCmd.Close acForm, &quot;frmConstraint&quot;<br>&nbsp;End If<br>rec.Close<br><br>any suggestions? i have spent almost all day on this!!
 
Just a quick observation<br>If rec.RecordCount &lt; 0 Then will never test true<br>If rec.RecordCount =&lt; 0 Then<br>or If rec.RecordCount &lt; 1 Then<br>&nbsp;&nbsp;<br>&nbsp;
 
wouldn't the easiest way be to go to the frmConstraint and for the OnLoad event type<br><br>if isnull(id_no) then<br>&nbsp;docmd.close &quot;frmConstraint&quot;<br>end if<br><br>id_no is the primary key so i know if there is no id_no, then there are no records. but this way isn't working. what am i doing wrong?&nbsp;&nbsp;<br>help!
 
i figured it out. From frmSwitchboard, i was using the argument acReadOnly to open my form frmConstraint. <br><br>that is what was causing all the problems. <br><br>so now i just open the form frmConstraint (not read only) and in the formOnLoad event of frmConstraint, i have the code: <br><br>If IsNull(id_no) Then<br>&nbsp;&nbsp;DoCmd.Close<br>End If<br><br>and it works! that darn Read-Only!! uggh.&nbsp;&nbsp;now i just lock the cells i want to protect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top