Control a subform from main form - ms-access

I have a main form Form_frmSaleand it contain a sub-form frmSale_subform.How can I "access" the fields in subform
For e.g with no subform i would do Sale_Date.Enabled = True
What code should i put if i want to control subform fields from main form(Suppose Sale_Dateis in a subform
I tried the following but its not working
Me.frmSale_subform.Sale_Date.Enabled = True
frmSale_subform.Sale_Date.Enabled = True

One way you should be able to do that is using:
Me.frmSale_subform.Controls("Sale_Date").Enabled = True
If that doesn't suite your fancy you can also reference http://access.mvps.org/access/forms/frm0031.htm for other ways to do it.

Related

How to pass value from subform to mainform ms access

I have a form with a subform (Datasheet view form). When i click a row in subform, i want pass that row value to text box in main form . In subform even wrote this
Private Sub Form_Click()
MsgBox (Noloan)
End Sub
But i don't know how to pass that subform form_click no_loan to mainform.textbox. Thanks for your help.
Additional data:In my db , i have a table which consist field No,NoLoan,Name. NoLoan Field value as i wanna clicked .From that table i create a subform/datasheet view ,subform name is T_Loan1. Then I create Main Form, name is FindLoan2. In that main/parent form i create text box, called Text7, and put T_Loan1 in subform object at footer.
I put this
=[Forms]![FindLoan2]![subformTLOAN].[Form]![Noloan]
in my Text7 Control and It's work.
Thank's for all attention.
Goto to the subform and click on the field which has the row value
Select Field property - click on events tab --> On Click --> Code Builder
Put below code in the Click event where Form_frmMain is your form name and Me.ID is the field.
Private Sub ID_Click()
Forms!FindLoan2.Text7 = Me.ID
End Sub
The best way is to write code that ignores the forms!names. If you copy the form, or change the sub form, or even drop the sub form into a different form, then all your code breaks.
To reference the textbox in the parent form from code, use:
me.Parent!Text7 = me!id
I am not sure which version of MS Access you are using, but it is also possible to use Tempvars to store values for use elsewhere if you have a complicated application which makes referencing another form/field/control difficult.
To create:
Tempvars.Add "TempVarName", TempvarValue
To use:
Tempvars!TempVarName
To remove:
Tempvars.Remove "TempVarName
I try to limit my use of them, as it becomes hard to manage. I am always careful about when I set the values and I ensure that they are removed after I am finished with them to avoid confusion or issues with values persisting when they shouldn't.

Access Value of a Control

On access, I have a navigation form (Stage) with a dropdown list (Modifiable84). How can I collect the value of these controls in each tabs (tabX, tabY ...) of my navigation form?
I've tried in a variable: X_var = Modifiable84.Value but I've got an error.
If you want to refer to a control on a specific subform, you need to use the subform name. E.g. X_var = Form1.Form.Modifiable84.Value where Form1 is the subform control name, not the form name.
Note that if you're using a navigation control, the form needs to be loaded.

Access - Show values from subform in texboxes

I have a form "frm_Results" with subform "subfrm_shv_Results" and three textboxes ("txt_Number", "txt_Name", 'txt_Surname").
I can show values of selected record in Debug.Print or MsgBox:
Debug.Print Form_frm_Results.subfrm_shv_Results.Form!Number.Value
Debug.Print Form_frm_Results.subfrm_shv_Results.Form!Name.Value
Debug.Print Form_frm_Results.subfrm_shv_Results.Form!Surname.Value
But it is possible to show values of "Number", "Name" and "Surname" in textboxes after click on record in subform "subfrm_shv_Results"?
Yes, you can do this, with a query as the contained object, you need to refer to the controls property, for example, you can set the control source of a textbox to :
= [Forms]![frm_Results]![subfrm_shv_Results].form.controls(0)
Similarly, with a continuous form or such like :
= [Forms]![frm_Results]![subfrm_shv_Results].Form!Surname
The result is not editable, but you can get around this by setting the value in VBA.
Make sure you use the name of the subform control, not the the name of the form contained.

How to put a label as link at the end of coloumns in a subform (Datasheet) in Access 2000?

I have a database created in access 2000. A form with a subform (datasheet - defaultview) in it. I have added a label at end of the coloumns in subform and given hyperlink to open the object present in database itself. But when the form open nothing is visible after the coloumn ? I got four coloumns and had hide two columns via onload event of subform. the code is below
Me.SubGroupname.ColumnHidden = True
Me.GroupName.ColumnHidden = True
Me.BNFno.ColumnHidden = False
Me.BNFno.ColumnWidth = -2
Me.SubGroupName1.ColumnWidth = -2
How can I make it visible so that it will appear as a link at each row ?
Please help me.
If I understand you properly, you cannot use Datasheet view to display a control at the end of a row. Switch to Continuous Forms view, it will give you more control, but you will have to work a little harder to get a nice layout.
Alternatively, add a click event to one of the existing columns.

setting control source property of a textbox of subform in its parent form in ms access?

I have a textbox on a subform the controlsource property of which is to be changed on click of a label on the parent form of the same. I have tried the following ways none of which worked at all,
Form_frmWOMAINMENU.[frmWOMAINSUBMENU].Form.[txtDate].Control.ControlSource _
= "Raised"
Forms("frmWOMAINMENU").[frmWOMAINSUBMENU].Form.[txtDate].ControlSource _
= "Raised"
Me.[frmWOMAINSUBMENU].Form.[txtDate].ControlSource = "Raised"
Can anyone suggest me how it works?
frmWOMAINMENU is the parent form and frmWOMAINSUBMENU is the subform.
Also, "Raised" comes from a sql query written as string in the vba code.
I tried the same in the subform like this:
me.txtDate.ControlSource="Raised"
and it worked fine.However,I cannot change control source of the textbox thrice in the subform.
It will be more like:
Forms!frmWOMAINMENU!frmWOMAINSUBMENU!txtDate.ControlSource = "Raised"
As long as on your parent form, the actual sub-form item is named "frmWOMAINSUBMENU" rather than "Subform1" or whatever the default naming is. Or in other words, the parent form is referred to by name and then the sub-form is referred to as whatever it's called on the parent form. Hope that makes sense : )