Results 1 to 14 of 14
  1. #1
    Join Date
    May 2007
    Posts
    92

    Unanswered: Transferring the text/value of a comboBox to another comboBox

    Hi Everyone,

    Does anyone knows how to transfer the value and text from 1 comboBox in form 1 to another comboBox in form 2 or form 3?

    For example, the comboBox text is tool in form 1 and i want to transfer the comboBox text "tool" to form 2 or form 3.

    Thank...

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    using some vba code behind an appropriate form event.....

    you can either "push" the value from the source form to the desitantion form

    forms!<mydestinationformname>.<mydestinationcontro lname> = <mysourcecontrolname>

    or you can "pull" it from the source from into the destination form

    <mydestinationontrolname> =forms!<mysourceformname>.<mysourcecontrolname>

    how you trigger the process is up to you. you could do it as part of the source combo box's on change event, you could attach the (relevant) fragment of code to a button on either form, you could get the second form to load the value on opening.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    May 2007
    Posts
    92

    ComboBox

    Hi Healdem,

    Regarding to your suggestion..

    I got the cboToolName1 in the Tool1Form and I want to make it the same cboToolName2 in the Tool2Form after closing the ToolForm and Opening up the Tool2Form.

    I try to put it on change event.. Still I can't get the result I want..


    <cboToolName2> =forms<Tool1Form>.<cboToolName1>

    forms!<Tool2Form>.<cboToolName2> = <cboToolName1>

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by StevenE
    Hi Healdem,

    Regarding to your suggestion..

    I got the cboToolName1 in the Tool1Form and I want to make it the same cboToolName2 in the Tool2Form after closing the ToolForm and Opening up the Tool2Form.

    I try to put it on change event.. Still I can't get the result I want..


    <cboToolName2> =forms<Tool1Form>.<cboToolName1>

    forms!<Tool2Form>.<cboToolName2> = <cboToolName1>


    the <> is a place holder, a typing convention to indicate that you put your values in there

    so replace <mysourceform>.<mycontrolname> with what ever your source form and source controls are called, say they are called "initialform" and "cmbselecttool" then you would use something like

    forms!Initialform.cmbselecttool
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    May 2007
    Posts
    92

    Transfer value from comboBox to another comboBox in another form

    Hi Healdem,

    I try these codes and it is not working...

    Can u explained in more details?

    Thank..

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Please post the code you tried
    George
    Home | Blog

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I have two forms// one called frmMain is a switchboard, the other is called frmSetDates

    frmMain is always laoded (it may not always be visinle but its always there, effectively its the main switchboard/menu
    frmSetDates essentailly offers the user a choice of dates.. the dat validation is doen in this form, so it always has valid dates (in effect this dform is used to select a specific date range based on accounting periods for reporting purposes. the user can select a specific period, week, range of dates

    there are two text boxes on each form frmMain has txtStartDate & txtEndDate; frmSetDates has tbDateFrom & tbDateTo
    to send the vlaues form one form to another I use....
    Forms!frmmain.txtStartDate = tbDateFrom
    Forms!frmmain.txtEndDate = tbDateTo
    ....in the frmSetDates OK button.. ie the user wants to use those vlaues, presses OK and frmSetDates pushes the values to frmMain

    it could just as easily be accomplished by putting some code in frmMain by puliing the values from frmSetDates
    txtStartDate = forms!frmSetDate.tbDateFrom
    txtEndDate = forms!frmSetDate.tbDateTo

    expcept that frmSetDates is a modal dialog and is only visible for a short time.. once the user has pressed OK the from is unloaded so it makes more sense to push the values from frmSetDaet, than it does to pull them into frmMain.

    I use the pull style approach to pull the values into say a report... when the report opens as part of the onload event I pull in the values required
    eg
    myformattedDatalable.caption = format(forms!frmMain.ttxstartDate,"dd mmm yyyy")
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    May 2007
    Posts
    92

    Transfer value

    Hi healdem,

    These are codes I try

    Private Sub Command4_Click()
    DoCmd.OpenForm "frmMain"
    Forms!frmmain.tbDateTo = txtStartDate
    End Sub


    but the codes not working...

    I press the value 55 in the frmmain but no value in the txtStartDate
    Last edited by StevenE; 09-03-07 at 06:30.

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    bear in mind the examples i gave are taken form an application I have

    the best thing to do is

    1) take note of the form you want to send the value to.. for the purposes of this answer we will call it frmMain
    2) take note of the control you want to sent the value to.. for the purposes of this answer we will call it mydestinationcontrol
    3) take note of the control you want to sent the value from.. for the purposes of this answer we will call it mysourcecontrol
    4) place a button on the source form.. for the purposes of this answer we will call it mysourceformbutton
    5) open the code window, or click the mysourceformbutton and place soem code in its on click event
    forms!frmMain.mydestinationcontrol = mysourcecontrol

    you will need to make whatever chanegs area appropriate for your requirements
    ie
    change frmMain to wahtever your destination form is called
    change mydestinationcontrol to wahtever your control on that form is called
    change mysourcecontrol to whatever your control on that form is called
    change mysourceformbutton to whatever your control on that form is called


    after that Im not sure I can help you that much, either Im mumbling in vba or you don't understand or a mixture of both. I dont really see how I can explain it more clearly based on your current response. I can only assume that my answers are pitched at to different a level of knowledge than you possess. This forum cannot attempt to teach you how to develop applications its merely here to help and assist, it cannot do, it cannot attempt to cover the basics.
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    May 2007
    Posts
    92

    Transfer Value

    Hi Healdem,

    I do as what you told me to do...

    I still got encounter these problem. I encounter the runtime error 2450...

    It say "Microsoft Access can't find the frmMain referred to in a macro expression or Visual Basic Code..

    Forms!frmMain.txtName = txtEmployee

  11. #11
    Join Date
    Nov 2003
    Posts
    1,487
    Ok...Try this:

    Copy and paste the following Function into a Code Module (if you don't already have it):

    Code:
    Public Function IsLoaded(ByVal strFormName As String) As Integer
       ' Returns True if the specified form is open in Form view or Datasheet view.
       Const conObjStateClosed = 0
       Const conDesignView = 0
       If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
          If Forms(strFormName).CurrentView <> conDesignView Then
             IsLoaded = True
          End If
       End If
    End Function
    Now...in the OnClick event of your Command button:

    Code:
    Private Sub Command4_Click()
       DoCmd.OpenForm "frmMain"
       Do Until IsLoaded("frmMain") = True: Loop
       Forms("frmmain").tbDateTo = Me.txtStartDate
    End Sub
    Do remember though, if you are supplying data to a ComboBox which has its Limit To List property set to Yes then you may run into problems sometime down the road. To add your supplied data to a Combo list will require additional code.
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  12. #12
    Join Date
    May 2007
    Posts
    92

    Transfer Value

    Hi CyberLynx,

    I got the value.. However, it is in number.. How can i change it to text??

    I got question to ask..

    Is these codes available for if i put these in form1 and i jump to form3 and such that it still can work..

    Eg. My sourceform is in form1 and my destinationform is in form3.

    Thank for your suggestions...

  13. #13
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by StevenE
    Hi Healdem,

    I do as what you told me to do...
    ...doubt that
    Quote Originally Posted by StevenE
    I still got encounter these problem. I encounter the runtime error 2450...

    It say "Microsoft Access can't find the frmMain referred to in a macro expression or Visual Basic Code..

    Forms!frmMain.txtName = txtEmployee
    Im guessing that the reason why you get that error message is that you didn't change the name of the destination form (in that example frmMain) to what your destination form is called
    OR
    you do have a form called frmMain but there is no control called txtName on it
    OR you do not have a control called txtEmployee on the current form
    OR two or more of the above are true.
    I'd rather be riding on the Tiger 800 or the Norton

  14. #14
    Join Date
    Nov 2003
    Posts
    1,487
    Quote Originally Posted by StevenE
    Hi CyberLynx,

    I got the value.. However, it is in number.. How can i change it to text??

    I got question to ask..

    Is these codes available for if i put these in form1 and i jump to form3 and such that it still can work..

    Eg. My sourceform is in form1 and my destinationform is in form3.

    Thank for your suggestions...
    With regards to your first question:

    I'm assuming (and only because of the control's name - tbDateTo) that we are dealing with a Date here. Now I could of course be mistaken and if so, please let me know. What does the data look like that you are getting?

    If what you mean is that you prefer not to have the date in "Short Date" format (07/01/2007) then simply change the code to produce the format you want.

    If you want the format to be in "Medium Date" format (07-Jan-07) then make the code line:

    Code:
    Forms("frmmain").tbDateTo = Format(Me.txtStartDate, "Medium Date")
    If you want the format to be in "Long Date" format (January 7, 2007) then make the code line:

    Code:
    Forms("frmmain").tbDateTo = Format(Me.txtStartDate, "Long Date")
    OR

    Select the format you want from the Format property of the tbDateTo TextBox Control
    __________________________________________________ __________

    As to your second question....

    The IsLoaded function should go into a main code Module (not a Form Code Module) and for this reason: If you place the function into a main code module then the function is available to ALL aspects of Access since it is declared as Public.

    Now, you can have the IsLoaded function code in every Form module but then that would be a lot of unnecessary duplicate code.

    The code located within the OnClick event of your command button (below):

    Code:
    Private Sub Command4_Click()
       DoCmd.OpenForm "frmMain"
       Do Until IsLoaded("frmMain") = True: Loop
       Forms("frmmain").tbDateTo = Me.txtStartDate
    End Sub
    can be applied to the OnClick event of any button on any Form. As a matter of fact (just to confuse you more) you can also create a Function in a main code module and declare it a Public to do the same thing. If you plan on using the code in more than one location then it's a good idea to create a public function so as not to have so much duplicate code. For example:

    Code:
    'Place into a Database Code Module...
    Public Function SetTbDateToBox (Frm As String, CtrlFrom As Control, CtrlTo As Control) As Integer
       'This function will Return 1 if successful and 0 if it fails.
       On Error Goto Error_SetTbDate
       DoCmd.OpenForm Frm
       Do Until IsLoaded(Frm) = True: Loop
       CtrlTo = CtrlFrom
       SetTbDateTo = 1
    
    Exit_SetTbDate:
       Exit Function
    
    Error_SetTbDate:
       MsgBox"Err.Number & " - " & Err.Description", vbExclamation, "Error In SetTbDate Function"
       Err.Clear
       Resume Exit_SetTbDate
    End Function
    It's more code because we've also added Error Trapping this time.
    To use this function you would Call it from again, the OnClick Event of your Command button:

    Code:
    Call SetTbDateTo("frmMain", Me.txtStartDate, Forms("frmmain").tbDateTo)
    OR

    Code:
    If SetTbDateTo("frmMain", Me.txtStartDate, Forms("frmmain").tbDateTo) = 0 Then
       MsgBox "DOH!!!"
    End If
    Now...if we're talking about SubForms (on frmMain) as well then you can access that SubForm like this:

    Code:
    Forms("frmMain")("SubFormNameOnfrmMain").Form.tbDataTo
    The bottom line is...there is always a lot of ways to do something in MS-Access.

    There....blah

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •