Main form to sub form (1 Viewer)

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
Hello,

I got a main form with a save ,edit , view etc. I then have a sub form within it.

The problem is that the buttons on the main form don't seem to apply to the sub form.

For example my form is suppose to load in view mode and then if I want to make changes I click edit .

However the sub form loads but it still can be edited in view mode on my main form. Can someone help with this thanks
 

WayneRyan

AWF VIP
Local time
Today, 02:04
Joined
Nov 19, 2002
Messages
7,122
Ken,

If the data can be edited in "view mode", then you could have bound controls,
coding error, or something else.

Need more info.

A sample would help.

Wayne
 

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
This is when the form loads

Private Sub Form_Load()
AllowEdits = False
End Sub


But the sub form does not load like this. The sub form can be edited when the form is loaded . The only thing I can think of is to put this code in the subform also,but then when I click the edit button on the main form

Private Sub cmdEdit_Click()
AllowEdits = True
End Sub


The subform then can not be edited


I basically want the main form buttons and VBA code to apply to the sub form.
 

CharlesWhiteman

Registered User.
Local time
Today, 02:04
Joined
Feb 26, 2007
Messages
421
It sounds like you have customised the properties ont he main form. But you can also open the subform in its own window, fromthe objects window and customise the properties relating to the subform.
 

jkl0

jkl0
Local time
Yesterday, 21:04
Joined
Jun 23, 2006
Messages
192
And after you change allowedits to False on the subform:

When you click the edit button on the main form you can use,

Me.subfrmName.Form.Allowedits = True
 

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
So basically I have to code this on the main form for the edit button

Private Sub cmdEdit_Click()
AllowEdits = True
Me.subfrmName.Form.AllowEdits = True
End Sub

but for some reason it does not work
 

RoyVidar

Registered User.
Local time
Today, 03:04
Joined
Sep 25, 2000
Messages
805
Often an error occurs because the subform name differs from the subform control name. The latter is what is used when referencing subform controls, properties and methods.

One easy way of obtaining the correct subform control name, would be to utilize the expression builder, for instance from a controlsource in the main form. Doubleclick through forms, loaded forms, main form, subform, then on a control on the subform. This should give you the correct reference.

A bit more info in this MS KB http://support.microsoft.com/?kbid=209099

To get better assistance, something more than "doesn't work", is often required. For instance error messages, what happens, what doesn't happen that should happen...
 

CharlesWhiteman

Registered User.
Local time
Today, 02:04
Joined
Feb 26, 2007
Messages
421
why not just change the object properties? and prevent edits that way in a second?
 

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
Can someone help me out. If someone could get the buttons on the right to work with the sub form would help me a lot.

I have included the part which Im finding difficult
 

Attachments

  • db1.zip
    28.4 KB · Views: 109

boblarson

Smeghead
Local time
Yesterday, 18:04
Joined
Jan 12, 2001
Messages
32,059
Okay, a few things:

1. I changed your field Student# to StudentNum as you don't want to use special characters in your object names.

2. I changed your form names to not have spaces (it's easier for coding and I would highly suggest you get in that habit).

3. I changed the subform container name to be the same as the subform name for simplicity's sake because the syntax to refer to a subform needs to reference the CONTAINER name, not the subform name, but if they are the same, it makes it simpler.

4. I changed the subform itself to set the default AllowEdits and AllowDeletions to NO. Then you don't need the form load code.

5. I changed the code in the main form buttons to reflect the actual syntax.

Everything now works.
 

Attachments

  • db1_rev04-02-2007.zip
    18.5 KB · Views: 110

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
Is there a way to keep the main form locked until I click on the edit button.
So basically the button controls the main form and subform
 

boblarson

Smeghead
Local time
Yesterday, 18:04
Joined
Jan 12, 2001
Messages
32,059
Set the AllowEdits property of the main form to No and then in the code behind the buttons just add:

Me.AllowEdits = True (for the edits)

and

Me.AllowEdits = False (for the view)
 

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
I encountered another problem. I added a new button to the main form ,however when I click on new button the sub form come up blank.

I was wondering if you could help with this thanks again.

BTW what does me stand for in Me.AllowEdits
 

boblarson

Smeghead
Local time
Yesterday, 18:04
Joined
Jan 12, 2001
Messages
32,059
When you say you added a new button to the main form, what do you want that button to do?

Also, Me. is a shortcut reference to the current form, or report, that you can use if the code you are using it in is actually on that form or report.
 

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
Iv used wizard to to create a new record.

When I click on the new record button the form is suppose to come up with empty fields but instead class sub form come up blank.

Iv included the database for you to see the problem
 

Attachments

  • db1_rev04-02-2007.zip
    29.5 KB · Views: 78

boblarson

Smeghead
Local time
Yesterday, 18:04
Joined
Jan 12, 2001
Messages
32,059
I may have accidentally set that form to AdditionsAllowed = No. Open the subform directly and verify that it's AdditionsAllowed is set to YES and not NO.
 

kenshinx1

Registered User.
Local time
Today, 02:04
Joined
Nov 21, 2006
Messages
24
That does not seem to be the problem.

When I try to add a new record from a different form it works correctly. only it doesnt work from the main form.
 

Users who are viewing this thread

Top Bottom