Link to home
Start Free TrialLog in
Avatar of jaisonshereen
jaisonshereen

asked on

How to get the value of access combo box from one form to another form?

How to get the value of access combo box from one form to another form?
Avatar of jaisonshereen
jaisonshereen

ASKER

i just want to pass a value in one form1 combobox1  to form2 ....


where in form2 ...there is a button1 ...on the click event of the button i can write some thing like..


button1_click()


if (form1 combobox value is 3)
then

do this

end if


they

button1_click

if not isnull(forms.form1.combobox) then

me.controlName = forms.form1.combobox

Else

Exit Sub

End If

End Sub
why we are using :

if not isnull(forms.form1.combobox) then
??
so that you don't get an error if the is no value in the combo box.  Just an optional error control measure
when i type


forms.      i am getting options to select ..


application,count,item,parent

i dont need to select none of this ..right?

i can type forms.form1.comboboxname="value"


right?
Not working ..


438 , object doesn't support this property or method ...


i am using a subform so i need to put the parent form name also???

just type forms.Form1.combobo1=me.controlname

form1 is the name of the form1

combox1 is the name of the combobox on form1 that contain the data you want to import

control name is the name of the controm on the same form as the button that you want to input the data

I note that form1 has to be open for this to work
also its best you put the combobox in form2 as an unbounded combobox the you code will be

button1_click

if not isnull(Me.combobox) then

Me.controlName = Me.combobox

Else

Exit Sub

End If

End Sub

nope!!



is this what you expected?

me.controlbox=me.combobox_name
 
if(Forms.subform1.combobox_name="value"
 
then
 
do something
Else 
 
do something
End if

Open in new window

If you are using a subform the syntax is

Forms.FormName.SubformName.Form.ControlName
oops

control name is the name of the controm on the same form as the button that you want to input the data


i am not supposed to change the design..of the form..!!

So i cannot make a controlname
You can do virtually anything. But some are more difficult than others. I like to stick to the easy option

Your code should look like the one below. Remember Me means the current form. If you are refering to another form or subform then you have to write the complete reference to that object
Private Sub Command61_Click()
 
If Not IsNull(Me.try) Then
 
Me.re = Me.try
 
Else
 
Exit Sub
 
End If
 
End Sub

Open in new window

the code I have just send put the value selected in the combobox named try in a textbox named re

If the is nothing in try nothing happens
nope still not working!!
ok let me check
1) send a copy of your code

2) explain the setup of your two forms. What are they called, what is the name of the subform, where are the combobox, textbox and button (on which form or subform.

3) or better still just send a copy of your db
This is what i did its still not working;



Private Sub Command61_Click()
 
Dim re as textbox
 
 
Me.re = Me.Combobox1
 
if(Me.re="value")
 
then
 
do something
Else 
 
do something
End if
End Sub

Open in new window

This is the form!
Form.JPG
I am trying to get the value of year ...using the button below i rounded ...


i went to the click event of the button and i am trying to get the value ,,,of the year ...

search is another form... and one which i click the botton is another form!
you don't need to dim re as textbox

when you type me. you should get an option list. Start typing the name of your textbox (do you know the name of your textbox?) and it will come up in the option list

I notice you have copied the name of my button Command_61. It would be a strang coincidence if your button has the same name.

To use a button onclick open the form in design view. double click on the button to open the procedure dialog. From the drop down in the onclick field in the event tab click event procedure. Then click on the like box at the right of the field. Then write your code between Private Sub ButtonName_Click() and End Sub
This is the click event.... here i need to get value!
Private Sub Cmd_POSBrief_Click()
On Error GoTo Err_Cmd_POSBrief_Click
 
    Call Project1.Form_T_F900_GeneralSearch.CheckForNullSearch
    
    FixSearchCriteria
    
    DoCmd.OpenReport "T_043_POSBriefReport", acViewPreview
 
Exit_Cmd_POSBrief_Click:
    Exit Sub
 
Err_Cmd_POSBrief_Click:
    ApplicationError Err.Number, Err.Description, "Form_T_F130_ViewRollupPromotions\Cmd_POSBrief_Click"
    Resume Exit_Cmd_POSBrief_Click
 
End Sub

Open in new window

Like this??
Private Sub Cmd_POSBrief_Click()
On Error GoTo Err_Cmd_POSBrief_Click
 
    Call Project1.Form_T_F900_GeneralSearch.CheckForNullSearch
    
    FixSearchCriteria
    
    me.textboxname=me.comboboxname
    if (me.textboxname-"2007") then
    DoCmd.OpenReport "T_043_POSBriefReport", acViewPreview
    Else
    DoCmd.OpenReport "T_043_POSBriefReport2", acViewPreview
    End If 
Exit_Cmd_POSBrief_Click:
    Exit Sub
 
Err_Cmd_POSBrief_Click:
    ApplicationError Err.Number, Err.Description, "Form_T_F130_ViewRollupPromotions\Cmd_POSBrief_Click"
    Resume Exit_Cmd_POSBrief_Click
 
End Sub

Open in new window

looks like both the search form and the form with the botton are search form of another form

And its not clear where you want to insert the year value. If you want to open a report then that's a totally different code
Please note "Form_T_F130_ViewRollupPromotions" this is current form !!
Actually i need to open two type of report according to the year value ...!

I form with combobox name is different .. that is why i told it is a subform
You are not getting anything because you are typing comboboxname, textboxname ect..  

You have to use the actual names of these objects. To find their name go to their property dialog box. Click the other tab. Their names are in the first row. You can change the name if you want
:-)


T_F900_GeneralSearch is the form which having combobox
Combo_Year is the combobox name in the T_F900_GeneralSearch
Form_T_F130_ViewRollupPromotions is the form having the button
And above code which i given is the click event of the button. Cmd_POSBrief_Click()
This is what i did it as per your request ..its not working!
Private Sub Cmd_POSBrief_Click()
On Error GoTo Err_Cmd_POSBrief_Click
 
    Call Project1.Form_T_F900_GeneralSearch.CheckForNullSearch
    
    FixSearchCriteria
    
    
    if (Forms.Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch.Form.Combo_Year=2007) then
    DoCmd.OpenReport "T_043_POSBriefReport", acViewPreview
    Else
    DoCmd.OpenReport "T_043_POSBriefReport2", acViewPreview
    End If 
Exit_Cmd_POSBrief_Click:
    Exit Sub
 
Err_Cmd_POSBrief_Click:
    ApplicationError Err.Number, Err.Description, "Form_T_F130_ViewRollupPromotions\Cmd_POSBrief_Click"
    Resume Exit_Cmd_POSBrief_Click
 
End Sub

Open in new window

That's to open the form

docmd.OpenReport ("reportname",acViewPreview,,year = chr(34) & forms.formname.subformsearchname.comboname & chr(34))

If you send a copy of the db remove db I can fix it for you. Looks like you are getting mixed up with these long name
docmd.OpenReport ("reportname",acViewPreview,,year = chr(34) & forms.formname.subformsearchname.comboname & chr(34))


Can you explain this?
how will this a solution for above?
T_F900_GeneralSearch is the form which having combobox
Combo_Year is the combobox name in the T_F900_GeneralSearch
Form_T_F130_ViewRollupPromotions is the form having the button
And above code which i given is the click event of the button. Cmd_POSBrief_Click()

ok try the code below and tell me what happens. That is just a trial
Private Sub Cmd_POSBrief_Click()
 
dim str as string
 
str = forms.T_F900_GeneralSearch.Combo_Year 
 
msgbox (This report is for the year "str")
 
End Sub

Open in new window

sorry line 7  should be

msgbox ("This report is for year" & str)
Nope its not working..its saying  438 , object doesn't support this property or method ...

whenever i type


Forms and a [DOT] after that ..

i am getting options to select ..


application,count,item,parent

i am NOT getting  T_F900_GeneralSearch


will it be right?
From the picture you send it looks like Form_T_F130_ViewRollupPromotions is your main form

then you have 5 subforms on it and the button is on one of the subform, not on the Form_T_F130_ViewRollupPromotions as you mentioned. The code will never work unless you are precise.

I think that I know have a better understanding of your form setup. So I will retry the message box code


Private Sub Cmd_POSBrief_Click()
 
dim str as string
 
str = Forms.Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch.Form.Combo_Year 
 
msgbox (This report is for the year "str")
 
End Sub

Open in new window

Opps forgot the " " again
Private Sub Cmd_POSBrief_Click()
 
dim str as string
 
str = Forms.Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch.Form.Combo_Year 
 
msgbox ("This report is for the year" & str)
 
End Sub

Open in new window

its not working

in the form

Form_T_F900_GeneralSearch


me.Combo_Year..i can get the value!!

But not in Form_T_F130_ViewRollupPromotions

:-(
send a copy of your latest code
What do you mean a get the value Did you try using the msgbox to check if the value is being picked up
aha......!!


there was another subform for Form_T_F130_ViewRollupPromotions called T_F900_GeneralSearch_SubForm

where this Form_T_F900_GeneralSearch is located ...he he!




Forms.Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch_SubForm.Form_T_F900_GeneralSearch.Form.Combo_Year

this will work i guess!!
 
ASKER CERTIFIED SOLUTION
Avatar of Sheils
Sheils
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
nope....

This is my present code still not JOY.

I thing to note:

I cannot see the subform ...... Form_T_F900_GeneralSearch_SubForm any of the listing in Access Forms

I can see only in the window of T_F130_ViewRollupPromotions... when i click on the search box..box will highlights..

then if i got to properties ..others i can see the name as "Form_T_F900_GeneralSearch_SubForm"
Private Sub Cmd_POSBrief_Click()
On Error GoTo Err_Cmd_POSBrief_Click
 
    Call Project1.Form_T_F900_GeneralSearch.CheckForNullSearch
    
    FixSearchCriteria
    
    
    if (Forms.Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch_SubForm.Form_T_F900_GeneralSearch.Form.Combo_Year=2007) then
    DoCmd.OpenReport "T_043_POSBriefReport", acViewPreview
    Else
    DoCmd.OpenReport "T_043_POSBriefReport2", acViewPreview
    End If 
Exit_Cmd_POSBrief_Click:
    Exit Sub
 
Err_Cmd_POSBrief_Click:
    ApplicationError Err.Number, Err.Description, "Form_T_F130_ViewRollupPromotions\Cmd_POSBrief_Click"
    Resume Exit_Cmd_POSBrief_Click
 
End Sub

Open in new window

so i guess i need to use (exclamation) some where in between !!
Delete your code and insert the one below and let me know what happens
Private Sub Cmd_POSBrief_Click()
    
 dim str as string
 
dim str as string
 
Str =
Forms!Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch_SubForm.Form!Combo_Year
 
msgbox ("This report is for the year" & str)
 
End Sub

Open in new window

You can get away with the dots and exclamation but I am sure you don't have Form_T_F900_GeneralSearch_SubForm inside itself which is what your code is saying
but try the little test using the msgbox first once this work we can move on to the report. NO report code until we are sure that we have the right reference for the combo box

i am getting till here ..

when i typed

me and [DOT] ..i am getting Form_T_F900_GeneralSearch_SubForm  automatically

so now

me.Form_T_F900_GeneralSearch_SubForm.Form.  

then what should i follow!???

yeeeeeeeeeeeeeeessssssssssssssssssss

its working

me.Form_T_F900_GeneralSearch_SubForm.Form.Combo_Year


worked ...he he !! :-D


Thanks a lots yaar!!
me.Form_T_F900_GeneralSearch_SubForm.Form.Combo_Year
ok settle down. What is working. The whole thing or just the message box
ok whole thing is working!! thanks!
Thanks a ton!