Subform to Form problems

jdwazere

Registered User.
Local time
Today, 06:49
Joined
Feb 17, 2007
Messages
22
Im making a program for my college coursework.
On one of my forms it displays an Order with its details such as the supplier and the date of the order, and within the page there is a subform which shows all the different items on the order. Next to the subform but on the parent form is a check box that shows whether or not the order has been completed. I want it so even when it has been completed, it disables(greys out) all the records in the subform for that particular order. How is this done?
 
the enabled/locked properties for a control work together

enabled yes - locked no - normal
enabled yes -locked yes - can enter, but cant edit
enabled no - locked yes - cant enter / or change
enabled no, - locked no - special, cant enter, and greys

therefore in your case, in the main form, you need to set the subform properties to enabled no, locked no
 
I know what enabled and locked properties do...I just need help in changing two of the fields' enabled properties to false when the 'order completed' button is checked
 
Hello,

Go to Form properties, and under the events tab, click the three dots next to the "On Current" event and use the following code. I am assuming your checkbox is named OrderComplete, and that you have a few fields like Supplier, and OrderDate.

Private Sub Form_Current()

If Me.OrderComplete.Value = -1 Then
Me.Supplier.Enabled = False
Me.OrderDate.Enabled = False
Else
Me.Supplier.Enabled = True
Me.OrderDate.Enabled = True
End If

End Sub

This code runs everytime a new record is brought up on the form and checks the see the the checkbox named OrderComplete is checked (-1 means it is checked). If the box is checked, (meaning the order is complete) it disables the two controls for that particular record, if the box is unchecked, it enables the two controls.

You can put as many controls as you want inside of the If Statement. Note that another good way that I use besides disable is to use .Locked = True and .Backcolor = 8454143 (.Locked = False and .Backcolor = -2147483643). This is so your users can tell if the control is locked or not based on the backcolor, yellow means locked, white means editable.

Hope this was helpful!
 
Well thankyou that was helpful and there is an order date and supplier ID but its not them i need to change. The fields that i want to edit are on the subform, and the order completed check box is on the parent form, so i think i may have to type the whole pathline of the object on code builder instead of just putting the name.
 
You are correct, I misread that it was in a subform, sorry.

To reference a subform control you use the following code:

Me.subFormName.Form![FieldName].Enabled = False

So...

If Me.OrderComplete.Value = -1 Then
Me.subformName.Form![Supplier].Enabled = False
Me.subformName.Form![OrderDate].Enabled = False
Else
Me.subformName.Form![Supplier].Enabled = True
Me.subformName.Form![OrderDate].Enabled = True
End If

Let me know if this works for you.
 
The only problem now is that it errors saying 'cannot disable a control while it has focus' based on the field 'Stock ID' which is the first field to appear in the subform

so far i have in...
Private Sub Form_Current()
If Me.OrderCompleted.Value = -1 Then
Me.query_subform_subform.Form![Order Quantity].Enabled = False
Me.query_subform_subform.Form![Stock ID].Enabled = False*
Else
Me.query_subform_subform.Form![Order Quantity].Enabled = True
Me.query_subform_subform.Form![Stock ID].Enabled = True
End If
End Sub

*=the line of the debug
 
You have to move the focus to a non disabled control before disabling the Stock ID one.

Use Me.YourOtherControl.SetFocus to move it before the other code tries to disable it.
 
Well now more problems
since there were no other enabled fields, i had to create one to act as something to set focus upon, i have made the property of the text box to be invisible...but it blatenately ignored it and displayed it any way

Also another problem is that now it just disables all the fields no matter whether the order completed box is checked or not

heres a picture of the form:
editorderformpicka5.png


and here is the coding so far:
Private Sub Form_Current()
Me.query_subform_subform.Form![txtFocus].SetFocus
If Me.OrderCompleted.Value = 0 Then
Me.query_subform_subform.Form![Order Quantity].Enabled = True
Me.query_subform_subform.Form![Stock ID].Enabled = True
Else
Me.query_subform_subform.Form![Order Quantity].Enabled = False
Me.query_subform_subform.Form![Stock ID].Enabled = False
End If
 
Well now more problems
since there were no other enabled fields, i had to create one to act as something to set focus upon, i have made the property of the text box to be invisible...but it blatenately ignored it and displayed it any way

Also another problem is that now it just disables all the fields no matter whether the order completed box is checked or not

heres a picture of the form:
editorderformpicka5.png

you can kinda see what it looks like

and here is the coding so far:
Private Sub Form_Current()
Me.query_subform_subform.Form![txtFocus].SetFocus
If Me.OrderCompleted.Value = 0 Then
Me.query_subform_subform.Form![Order Quantity].Enabled = True
Me.query_subform_subform.Form![Stock ID].Enabled = True
Else
Me.query_subform_subform.Form![Order Quantity].Enabled = False
Me.query_subform_subform.Form![Stock ID].Enabled = False
End If
 
Last edited:
As the code suggested earlier, you should use -1 instead of 0, and then reverse the True and False back to it was previously:

Private Sub Form_Current()
Me.query_subform_subform.Form![txtFocus].SetFocus
If Me.OrderCompleted.Value = -1 Then
Me.query_subform_subform.Form![Order Quantity].Enabled = False
Me.query_subform_subform.Form![Stock ID].Enabled = False
Else
Me.query_subform_subform.Form![Order Quantity].Enabled = True
Me.query_subform_subform.Form![Stock ID].Enabled = True
End If

You can set the focus to a button if you wish, in a datatable setting the property to visible = false doesn't do anything, you'd have to manually hide it by dragging the column width to 0.
 
Last edited:
O dear its still not doing much

Now the problem is since the focus has moved to this text box, the two fields do not become disabled

If I changed the width of the field that i want it to focus on(in preview(datasheet) mode), so that it doesnt show up, does it automatically appear invisible everytime on the form?

But before i had the textbox it just used to set both fields to disabled once and then it cant be changed, even when the ordercompleted box was unchecked
 
Hmm,

Can you post the database here so we can take a look at it, it seems like it should work.

Are there any buttons on this form that you can set the focus to? It sounds weird to make a textbox just so you can set the focus.

If you post the database here I can take a look at it tonight or over the weekend and maybe I can get a clearer idea of what exactly is going on. Because your code worked earlier (except that you had to change the focus) that code SHOULD be correct, as long as we can find something to focus.
 
surely the ordercompleted button is on the main form

if so, then you can disable the subform by setting its properties to locked no and enabled no

is the ordercompleted button on the subform. if so, why?

the subform deals with individual order lines, not the order itself

(i would have thought)

-------
to evaluate booleans, i would NEVER use values like 0 or -1

if its a true boolean yes/no, then use true and false

its easier to read, and is more syntactically correct anyway
 
O dear its still not doing much

Now the problem is since the focus has moved to this text box, the two fields do not become disabled

If I changed the width of the field that i want it to focus on(in preview(datasheet) mode), so that it doesnt show up, does it automatically appear invisible everytime on the form?

But before i had the textbox it just used to set both fields to disabled once and then it cant be changed, even when the ordercompleted box was unchecked

Your enabled/disabled is not changing because you're using the On_current event to set the state of the controls. Move your code to the On_click event of the check_box control.

Also you can get away with shortening your code by making it say
Code:
Me.query_subform_subform.Form![Order Quantity].Enabled = not Me.OrderCompleted.Value
Me.query_subform_subform.Form![Stock ID].Enabled = not Me.OrderCompleted.Value

This way you don't need the IF/THEN statements and your endabled/disabled gets updated to the opposite of OrderCompleted
 
The code I posted earlier should be put in both On Current and on Click (On click for when changed, and on current for future when surfing the records).

I will have to try your shortened version of the code sometime for checkboxes, the code I pasted was originally for using a button.
 
Everything works fine and ive copied and pasted the code into both on current and on click...except when I change a field of a record, and then click on the check box again and it says 'cannot disable a control when in focus'
There are no other enabled objects in the subform so obviously it will have to focus on a object in the parent form, but where do i put the code to focus say if i wanted to focus on a command button called cmdOrder?
 

Users who are viewing this thread

Back
Top Bottom