exit a form if condition not true


J

Jean-Paul

Hi

In the OnOpen property of my form I have following code:

If IsNull(Forms!klasniveau!Naam_ll) = True Then
If IsNull(Forms!klasniveau!jaar_zoek) = True Then
Me.RecordSource = "SELECT leerlingen.* FROM leerlingen
WHERE Leerlingen.[Nu nog leerling] = [Forms]![klasniveau]![Nu_ll] AND
Leerlingen.[klas] = [Forms]![klasniveau]![klas_zoek] AND
Leerlingen.[afdeling] = [Forms]![klasniveau]![afdeling_zoek] ORDER BY
leerlingen.Naam_ll;"
Else
Me.RecordSource = "SELECT leerlingen.* FROM leerlingen
WHERE Leerlingen.[Nu nog leerling] = [Forms]![klasniveau]![Nu_ll] AND
Leerlingen.[jaar] = [Forms]![klasniveau]![jaar_zoek] AND
Leerlingen.[klas] = [Forms]![klasniveau]![klas_zoek] AND
Leerlingen.[afdeling] = [Forms]![klasniveau]![afdeling_zoek] ORDER BY
leerlingen.Naam_ll;"
End If
Me!Knop32.SetFocus
Else
If Me.RecordsetClone.RecordCount = 0 Then
Me.RecordSource = "SELECT leerlingen.* FROM leerlingen
WHERE leerlingen.Naam_ll Like '" & "*" &
Replace(Forms!klasniveau!Naam_ll, "'", "''") & "*" & "'ORDER BY
leerlingen.Naam_ll;"
If Me.RecordsetClone.RecordCount = 0 Then
If MsgBox("Naam komt niet in bestand voor?",
vbExclamation + vbOKOnly, "Let op!") = vbOK Then
End If
Else
Me!Knop32.SetFocus
End If
Else
Me.RecordSource = "SELECT leerlingen.* FROM leerlingen
WHERE Leerlingen.[Nu nog leerling] = [Forms]![klasniveau]![Nu_ll] AND
leerlingen.NAAM_ll= '" & Replace(Forms!klasniveau!Naam_ll, "'", "''") &
"' ORDER BY leerlingen.Naam_ll;"
Me!Knop32.SetFocus
End If
End If

This code searches for a students name in a table "leerlingen"

When there is no mach the form opens blank...
Is there a way to leave (adn close) the form when nothing is found?

Thanks
 
Ad

Advertisements

B

Brendan Reynolds

When there is no mach the form opens blank...
Is there a way to leave (adn close) the form when nothing is found?

Add the line ...

Cancel = True

.... to cancel the opening of the form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top