Solved

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

Posted on 2008-10-23
53
270 Views
Last Modified: 2013-11-28
How to get the value of access combo box from one form to another form?
0
Comment
Question by:jaisonshereen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 30
  • 23
53 Comments
 

Author Comment

by:jaisonshereen
ID: 22792839
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


0
 
LVL 16

Expert Comment

by:Sheils
ID: 22792889
they

button1_click

if not isnull(forms.form1.combobox) then

me.controlName = forms.form1.combobox

Else

Exit Sub

End If

End Sub
0
 

Author Comment

by:jaisonshereen
ID: 22792897
why we are using :

if not isnull(forms.form1.combobox) then
??
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 16

Expert Comment

by:Sheils
ID: 22792919
so that you don't get an error if the is no value in the combo box.  Just an optional error control measure
0
 

Author Comment

by:jaisonshereen
ID: 22792921
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?
0
 

Author Comment

by:jaisonshereen
ID: 22792931
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???

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22792948
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

0
 

Author Comment

by:jaisonshereen
ID: 22792998
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22792999
If you are using a subform the syntax is

Forms.FormName.SubformName.Form.ControlName
0
 

Author Comment

by:jaisonshereen
ID: 22793005
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
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793031
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793054
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
0
 

Author Comment

by:jaisonshereen
ID: 22793083
nope still not working!!
0
 

Author Comment

by:jaisonshereen
ID: 22793093
ok let me check
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793096
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
0
 

Author Comment

by:jaisonshereen
ID: 22793214
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

0
 

Author Comment

by:jaisonshereen
ID: 22793237
This is the form!
Form.JPG
0
 

Author Comment

by:jaisonshereen
ID: 22793248
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 ...

0
 

Author Comment

by:jaisonshereen
ID: 22793256
search is another form... and one which i click the botton is another form!
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793320
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
0
 

Author Comment

by:jaisonshereen
ID: 22793333
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

0
 

Author Comment

by:jaisonshereen
ID: 22793350
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793353
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
0
 

Author Comment

by:jaisonshereen
ID: 22793355
Please note "Form_T_F130_ViewRollupPromotions" this is current form !!
0
 

Author Comment

by:jaisonshereen
ID: 22793360
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
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793371
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
0
 

Author Comment

by:jaisonshereen
ID: 22793394
:-)


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()
0
 

Author Comment

by:jaisonshereen
ID: 22793439
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793441
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
0
 

Author Comment

by:jaisonshereen
ID: 22793452
docmd.OpenReport ("reportname",acViewPreview,,year = chr(34) & forms.formname.subformsearchname.comboname & chr(34))


Can you explain this?
0
 

Author Comment

by:jaisonshereen
ID: 22793453
how will this a solution for above?
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793465
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793468
sorry line 7  should be

msgbox ("This report is for year" & str)
0
 

Author Comment

by:jaisonshereen
ID: 22793504
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?
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793510
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793530
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

0
 

Author Comment

by:jaisonshereen
ID: 22793537
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

:-(
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793544
send a copy of your latest code
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793559
What do you mean a get the value Did you try using the msgbox to check if the value is being picked up
0
 

Author Comment

by:jaisonshereen
ID: 22793577
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!




0
 

Author Comment

by:jaisonshereen
ID: 22793583
Forms.Form_T_F130_ViewRollupPromotions.Form_T_F900_GeneralSearch_SubForm.Form_T_F900_GeneralSearch.Form.Combo_Year

this will work i guess!!
 
0
 
LVL 16

Accepted Solution

by:
Sheils earned 500 total points
ID: 22793625
Looks like it will.

It will help to use simpler names for your forms and adopt a simpler naming convention.

I use the prefix frm for all my forms and sfr for all subform. No spacing in the form or subform names so that I don't have to worry about under score.

Seems like you have a subform in a subform. Check this site for some syntax

http://www.mvps.org/access/forms/frm0031.htm
0
 

Author Comment

by:jaisonshereen
ID: 22793645
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

0
 

Author Comment

by:jaisonshereen
ID: 22793661
so i guess i need to use (exclamation) some where in between !!
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793688
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

0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793696
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
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793705
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

0
 

Author Comment

by:jaisonshereen
ID: 22793714
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!???

0
 

Author Comment

by:jaisonshereen
ID: 22793743
yeeeeeeeeeeeeeeessssssssssssssssssss

its working

me.Form_T_F900_GeneralSearch_SubForm.Form.Combo_Year


worked ...he he !! :-D


Thanks a lots yaar!!
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793748
me.Form_T_F900_GeneralSearch_SubForm.Form.Combo_Year
0
 
LVL 16

Expert Comment

by:Sheils
ID: 22793752
ok settle down. What is working. The whole thing or just the message box
0
 

Author Comment

by:jaisonshereen
ID: 22793792
ok whole thing is working!! thanks!
0
 

Author Closing Comment

by:jaisonshereen
ID: 31509514
Thanks a ton!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question