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

Branch when query returns no value.

Status
Not open for further replies.

Orcanut

Programmer
Sep 3, 2002
24
CA
The following code is supposed to open a new form (Notation Final) if the query on which this form is based contains data or close this form if the query has no data. It attempts however to open the new form in either case? Assistance is appreciated.

Private Sub Form_Open(Cancel As Integer)
' An error that is special cased.
Const conErrNoValue = 2427
On Error GoTo Err_Form_Open

If IsNull(RegistrationID) Then
GoTo Err_Form_Open 'Closes current form
Else
DoCmd.OpenForm "Notation Final"
End If
 
Not sure with the amount of code listed. What is RegistrationID and how is it set? Is it really Null? Perhaps change IsNull to also include Len(TRIM(RegistrationID)) < 1. That is if u permit zero length string in the database and it is a database field.

I've done some similar stuff to set defaults on forms, but typically use the Load Event or On Current.. etc. Check Order of Events as a suggestion. htwh,

Steve Medvid
&quot;IT Consultant & Web Master&quot;
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
If (IsNull(RegistrationID) OR Len(Trim(RegistrationID))) Then

htwh

Steve Medvid
&quot;IT Consultant & Web Master&quot;
e-Mail: Stephen_Medvid@GMACM.com

Chester County, PA Residents
Please Show Your Support...
 
Thanks I tried both neither works. The problem is RegistrationID either exists because the other criteria in the query are in place or it isNull because the query returns no records. If the query returns a RegistrationID I want a new form to open to work on the results of the query otherwise I want to simply close the current form.

 
Try using the RecordCount of the RecordsetClone

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
GoTo Err_Form_Open 'Closes current form
Else
DoCmd.OpenForm &quot;Notation Final&quot;
End If
End Sub

PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top