473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Close Form conditional on content in subform

22
I am looking to prevent a form closing and pop up an error message if one or more fields in a related form isnull.

I have a Main Form called "Job". In this main form is a subform called "JobTask" which is a continuous form. It contains a look-up box listing all the possible Tasks I could have for this job. Let's say I choose two (Task 1 and Task 2).

Within the subform the next field for each Task record is a check box (Choose a subtask). This checkbox opens another form "JobSubTask" which allows me to choose which SubTasks apply to the selected task (they can be different for each JOB). (For reference the TaskID is passed to the Form "JobSubTask" and so linking the Subtask to the Task)

At present it is possible to close the form "Job" without actually selecting the SubTasks for each Task. I wish to stop that.

I have been looking at code like that shown below:


[if nz(SubTaskID,"")="" Then go to missing]

However, I do not know, how to do this when the fields are on anotehr form.

Of course what I really need is to ensure that for EVERY Task selected, there is at least one SubTask selected.

Thanks
Mar 17 '08 #1
6 2183
marcf
17
Assuming I get what your asking for then its simple, not that I think your stupid but dont include the <> around subform ;)

if Me!<subform>!fieldname.value = "" then ....



As a tip I tend to disable the big red X in access and make users close forms via a big close button, that way you can validate all you like without having to muck around with events.

Cheers


Marc
Mar 17 '08 #2
Hulm1
22
Thanks for the reply. I tried the following in the Before Update and also the onclick event of the close button. No joy.

[Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me!JobTask_Edit_JobSubTask_List!SubTaskID.Value = "" Then GoTo missing
missing:
Call MsgBox("sorry: Not all fields completed.")
Cancel = vbCancel 'prevents the form closing, because it aborts the record save

End Sub]

Could it be because it is not recognising the link between the Form JobTask_Edit_JobSubTask_List and the Main Form "Job_Edit"?

(Sorry my form names are slightly different to that which I showed earlier). Being a little long winded I did not want to confuse!

I wanted to attach a screenshot in case it helps you, but I can't find that possibility

Thanks again
Mar 17 '08 #3
marcf
17
Sorry if it seems a bit scrappy but its probably the simplest way I can think of. By the way when your talking about a SUBFORM you mean a form within your form, or do you mean a separate form opened from your main one?

If Me!JobTask_Edit_JobSubTask_List!SubTaskID.Value = "" Then GoTo missing
missing:

Should be:

If Me!JobTask_Edit_JobSubTask_List.SubTaskID.Value = "" Then GoTo missing
missing:

Ahh hold on, are you using a combo box for the SubtaskID? As I recall combobox.value doesnt return the value your after, you have to refere to the column?

You could try:

If Me!JobTask_Edit_JobSubTask_List!SubTaskID.Column(1 ) = "" Then GoTo missing

The combobox.column(number) depends on how you set them up...

Infact as a test i'd create a button on your main form where the onclick method sets the label to the value of the combobox on the subform to test your referencing it right. Then simply keep changing the value on the subform and clicking the button on the main one to test it out...
Mar 17 '08 #4
Hulm1
22
I think I am out of my depth here!

Just to confirm the correct form structure

1) Main Form "Job_Edit"
2) Subform "Job_Edit_JobTask_List (contains a look-up for all the tasks in the table zmtTasks). It is a continuous form. Each record also has a check box which has an onclick event. This onclick event as follows:


Private Sub chkEdit_Click()

Dim sWhere$

Me.chkEdit = False
DoCmd.RunCommand acCmdSaveRecord

Me.RecordsetClone.Bookmark = Me.Bookmark
sWhere$ = "JobTaskID = " & Me.RecordsetClone("JobTaskID")
DoCmd.OpenForm "JobTask_Edit", , , sWhere$, , acDialog, Me.Parent.Name

End Sub

This opens the following form

3) JobTask_Edit. This has a subform
4) subform JobTask_Edit_JobSubTask_List. This is similar to form 2 (above) but looks up a list of subtasks from the table zmtSubTask.

And so to refresh the question. Every Task in form 2, should have a least one subtask connected to it in form 4. If not, I want it to be impossible to close Form 1 and for a message to pop up and say why!

I hope you understand!!

I should be clear that the above database was developed by a another. I am learning by leaps and bounds but I could not have developed the above layout. Hence if you still feel able to help, I probably need a bit more clear code!

Thanks again
Mar 17 '08 #5
marcf
17
Ok I think I get ya!

Easy fix:

1) Set the window(Jobtaskedit) to Modal, this means it cant be unfocused until its been closed.

2) Disable the red 'X' at the top of that window(jobtaskedit)

That way the user has to exit the form by the close button and you can do all validation knowing that its not being closed by any other windows!

Sorry for the delay in replying for some reason my topic notification didnt stick!
Mar 17 '08 #6
Hulm1
22
Sorry I think I need to bail out here. I am sure your advice is good but I just don't know how to implement it!

I can set the form to modal, but I don't think I have the correct code for doing what I want.

I guess I really need a blow by blow instruction set with code. I do not expect that so don't worry.

Thanks anyway
Mar 17 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: nectar | last post by:
Hello, In an Offers DB, I have a form with two fields BeginDate and EndDate. When clicking on a button, it opens a continous form with a DoCmd.OpenForm and a criteria based on the 2 dates...
1
by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
2
by: stpark22 | last post by:
Hello, I've constructed a form that contains a subform in Access 2003. I want to be able to set the tab order to tab through the fields of the main forms then tab through the fieldw of the subform...
9
by: saddist | last post by:
Hello, I just can't get thru it. I have a form and a subform in it. Subform is tabular and it displays a query(Id,name,date). In main form I have text field "enterDateFrom" and "enterDateTo". I...
3
by: andydawson | last post by:
Hi Guys, Wonder if anyone could help me out. I've got a form with a record source link to . The form has a subform embedded. The link between the two is a job number . I am trying (and...
27
by: tragaz | last post by:
Hi There, I'm a beginer in Access and VB. In my Database, I've got a form with a subform. the subform is a query from a table different than the table of the main form. those tables don't have a...
4
by: Jinzuku | last post by:
Hi, I've created a main form that populates a subform using 2 combo boxes, however I'm having difficulty trying to create a sum of the total amounts of the results of the population. I have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.