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

How to stop lauching pop up form when linked value is null?

Status
Not open for further replies.

Salyn

MIS
Nov 22, 2002
7
AU
Dear all,

I have designed a form with a sub form. User has to first save data in the main form, then an auto number ID will be assign to the row in the subform. Double clicking a field in the row of the subform will open a relevant pop up form with the linked ID.
How to stop this pop up form from launching if the linked value is null? Like the user has forgotten to save the data entry in the main form first.
At the moment, I can only disabled all buttons except back to main button with a reminder to save data first.

I tried this code below but it closes my main form instead of the blank sub form.

If IsNull(Me!txtBookId) Then
MsgBox " Please save Order entry first.",
DoCmd.Close

Thanks in advance for any help.
 
Just use...

If IsNull(Me!txtBookId) Then
MsgBox "Please save Order entry first."
Exit sub
End If

You code to open the subform goes here

AT the very beginning of the code for you button to open the subform........ Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Thank you Robert.

That was the first code I tried but it doesn't work. After the message, it continue to launch the pop up form.

By the way I am using Microsoft Access 2002 (XP).

Any more help please.
 
OKay....let's take a closer look...

You whole code should look somehting like:

Private Sub txtFieldName_DoubleClick()

If IsNull(Me!txtBookId) Then
MsgBox "Please save Order entry first."
Exit sub
End If

DoCmd.OpenForm "NameOfPopFormHere"

End Sub

With the above code, you are doing first checking to see if the particular field is Null.....is it is, display a messagebox to the user, then exit the sub immediately. If not, continue in the sub, and open the form....

It should work perfectly....the access version does not really matter in this instance.

If it is still not working, please post your code (do a copy paste, so I can see the exact syntax you have).

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Robert,

Thanks again. This time it won't open any pop up form.

My data flow is suppose to be like this, first enter data in the main form and select an item from the combo list in the subform. It allows multiple selection in the subform. Data has to be saved first to create the linked value( BookDetailID) to the pop up form.
Then double clicking a row in the subform should lauch the relevant pop up form for further data entry.
My problems was how to stop launching the pop up form if the linked value is null? That is, if the user forgot to save the data entry in the main form first.

When I applied the code in the individual pop up form , it doesn't stop lauching the form although the linked value was null. When I applied it to the sub form, it stop launching the pop up form completely even if it has been saved.

Below is my code in my sub form:
Private Sub cboServiceType_DblClick(Cancel As Integer)

On Error Resume Next
Dim stDocName As String
Dim stLinkCriteria As String
Dim lngBookDetailID As Long
Dim lngBookID As Long

If Not IsNull(cboServiceType.Value) Then
gServiceCodeId = cboServiceType.Value
lngBookDetailID = Me!fldBookDetailId
lngBookID = Me!fldBookId

stLinkCriteria = "BookDetailID=" & lngBookDetailID

If cboServiceType.Value = "2" Then
stDocName = "frm02"
If IsNull(Me!txtBookDetailId) Then
MsgBox "Please save Order entry first."
Exit Sub
End If
DoCmd.OpenForm stDocName, , , , , , stLinkCriteria
End If

' there are altogether 6 diferrent pop up forms.

End If
End Sub

Hope to hear from you soon. Thanks.

Salyn
 
First, try walking through the code on line at a time and evaluate the values.....are you 100% sure that cboServiceType.Value is not Null? This seems to me that you have to doubleclick the combo box, and if the combobox is null then don't go any further.....but you mentioned that it is a text box on a subform....perhaps your code is in the wrong place????

Second, instead of just evaluatfor Null, try also including evaluation for empty....Anywhere you are looking for nullshould be something like:

If IsNull(Field.Name) Or Field.Name = "" Then

This will also be true if the value is not truly null but is empty....there is a find line between empty and null....may be your problem. Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top