form/subform issue

ashu.doc

Registered User.
Local time
Yesterday, 23:15
Joined
Oct 8, 2012
Messages
24
can form and subform be on different pages like web? and can I put a hyperlink or button on main form to open subform as a different page?

I have a main form in which I have added a subform by subform wizard. When I am keeping the subform on the main form and entering data in subform corresponding to the main form, the data is entering well in the table of main form and subform, but what I want to do is that to put a hyperlink or button on main form which opens that subform and then when I enter the data in subform it should go into the main form corresponding to it.
 
What I understand from form/subform concept is that they both should be open together on the same screen to work together, is that correct? There should be a way to open the subform from the main form as a hyperlink or botton etc.??
 
when you create a form form form wizard, and select two tables, you have the choice to either create a form with subform or linked forms. Does it helpful to you? Then you get a hyperlink button on first form to open the second form but I am not sure if it features all the advantage of form-subform.
 
thats helpful, thanks. But I have one main form which I have designed sometime ago and have done quite a lot of work on it and added some subforms on the form, so I dont want to start from beginning and go through wizard channel. So is there anyway I can add the subform links now to add more subforms to the main forms, which I want to open on different page and not on the same page?
(the new subform's table is related as one to many with main form's table)
thanks again
 
First create an example form and then see the code behind the button which opens the next form. Is it possible for you to implement such code in your existing form with a button inserted by you manually.
 
Hi
As per your suggestion I have created a sample form with two table and forms. One table is about customers' mailing list and the other is for orders, customer one is related to order as one to many, with customer ID as primary key is mailing list table and a foreign key of the same in order table. the I have created a linked form, but I dont know what mistake I am doing that whatever orders I am entering for say customer ID 1, does not show the same customer ID 1 in orders table, it only shows 0. i am sending you the db as attachment, please have a look and suggest.
thanks

View attachment db3.zip
 
If you use a form and subform, then foreign key is automatically populated by access but in case of linked form it can not be done. In that case, we need to use some simple code.

I have put a code in Orders form in the before insert event. Just have a look at that. Also, there was default value of 0 in table orders for customer ID which I removed. Also, I created a Save button on mailing order form which is needed to pressed before going to linked form but if you want to avoid that button, copy the code from there and use it in the button which opens the linked form but before doing that, first try how it works.

Hope it helps.
 

Attachments

It is actually possible to define the LinkMasterFields of a subformcontrol to be a field or control in an entirely different form.

It requires a requery of the subformcontrol to track the movements in the other form (using the OnCurrent Event) but the key field will populate on new subform records.
 
If you use a form and subform, then foreign key is automatically populated by access but in case of linked form it can not be done. In that case, we need to use some simple code.

I have put a code in Orders form in the before insert event. Just have a look at that. Also, there was default value of 0 in table orders for customer ID which I removed. Also, I created a Save button on mailing order form which is needed to pressed before going to linked form but if you want to avoid that button, copy the code from there and use it in the button which opens the linked form but before doing that, first try how it works.

Hope it helps.

Thats working !! thanks a lot, there is little hitch, when I am clicking on that button it is showing an error msg that "Object doesn't support this property or method"
I am using access 2007, is that something to do with it? Because I have used your codes which may be designed on latest version ?
 
Also when I am trying to put more buttons with similiar codes, its showing an error highlighting this - Private Sub FilterChildForm()
Error- ambiguous name detected:FilterChildForm

I think its because I am copy and pasting the same codes for differrent buttons and just changing the name of button and name of forms.
Any suggestions?
 
its showing an error highlighting this - Private Sub FilterChildForm()
Error- ambiguous name detected:FilterChildForm

I think its because I am copy and pasting the same codes for differrent buttons and just changing the name of button and name of forms.

If you see in VBA editor, FilterChildForm() is called by ToggleLinkButton to open the child form and ensure about data entry and filtering position. If you copy same code and use for another form, you have to modify the code as well as change the name FilterChildForm() and then call it by the changed name.
 
when I am clicking on that button it is showing an error msg that "Object doesn't support this property or method"

I am also using A2007, so if you still not solved this, post your code and I will try to have a look.
 
The below lines are causing some problems:

' If ChildFormIsOpen() Then
'CloseChildForm
'Else
'OpenChildForm

I checked by putting ' before each line and could see that error goes off. Then I opened the link form by docmd command and no errors. In the linked form, the load and unload events cause the error.

Basically, these line were created while making form and link form.

Strangely, I have another dB in which I have same line of codes which works fine. I am yet to find answer.

ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "F_conferences") And acObjStateOpen) <> False

You can start another thread to get exact answer from experts. But meanwhile, even if those line has some issue in your dB, you can use alternate codes. Also, it has nothing to do with before insert event.

BTW, I think you are from India.
 
I have tried by putting ' like you said and code goes like this

Private Sub cmd_conferences_Click()
On Error GoTo cmd_conferences_Click_Err

'If ChildFormIsOpen() Then
'CloseChildForm
'Else
'OpenChildForm
FilterChildForm
End If
cmd_conferences_Click_Exit:
Exit Sub
cmd_conferences_Click_Err:
MsgBox Error$
Resume cmd_conferences_Click_Exit
End Sub

but when I tried opening the linked form it is showing another error:

Compile error:
EndIf without block If
 
I meant to say that I found these lines. Anyway do as below:

I form F_AllDetails, in the conference button put ' as shown below and you need to write a code with doCmd already included below:
Sub Command111_Click()
On Error GoTo Command111_Click_Err


' If ChildFormIsOpen() Then
'CloseChildForm
'Else
'OpenChildForm
'FilterChildForm
' End If
DoCmd.OpenForm "F_conferences"
FilterChildForm

Command111_Click_Exit:
Exit Sub

Command111_Click_Err:
MsgBox Error$
Resume Command111_Click_Exit

End Sub

Now in another form F_Conferences, in the load and unload event, put ' as shown below:
'If ParentFormIsOpen() Then Forms![f_alldetails]!Command111 = True

'If ParentFormIsOpen() Then Forms![f_alldetails]!Command111 = False

After this form shall open without errors, only thing, since we have put ' in some codes, so it will not able to check if the form is open or not. but anyway, you could try alternate codes or find some reason why above codes are causing a problem.
 

Users who are viewing this thread

Back
Top Bottom