Combo box value to update another combo box

mba_110

Registered User.
Local time
Today, 00:15
Joined
Jan 20, 2015
Messages
280
Hi everyone,


I have button on click event to open frmCreateAccount with the value assigned by me to be updated in frmcreateAccount cboGroup in order to do that i have make following code, but its opening with no value filled in cboGroup on frmCreateAccount.

Code:
Private Sub BtnContinue_Click()
If Me.Option1 = True Then
DoCmd.OpenForm "frmCreateAccount", acNormal, [cboGroup] = "Income", , acFormAdd, acDialog
Exit Sub
End If
End Sub

or in another words i would say, I want "Income" string which is already in cboGroup combo box list value and when frmCreateAccount open by clicking on frmAddnewAccount should select this value from that list.
 
Last edited:
Well, can't do that in the OpenForm method. You can pass a value with OpenArgs argument.

DoCmd.OpenForm "frmCreateAccount", acNormal, , , acFormAdd, acDialog, "Income"

Then code in frmCreateAccount Load event can populate cboGroup.

If Me.NewRecord Then Me.cboGroup = Me.OpenArgs
 
Last edited:
I did try your method but it still open without filling the combo box in cboGroup on frmCreateAccount.

I have attached the db.
 

Attachments

Not sure why, but if you open the form in addNew and check for newRecord it comes up false. You code never ran. I would simply check if you passed in an argument.

Code:
Private Sub Form_Load()
 
 If Not Trim(Me.OpenArgs & " ") = "" Then
    Me.cboGroup = Me.OpenArgs
 End If

  Me.chk1.Value = False

End Sub
 
I place that code that June7 offered in my Form Current event ?

DBGuy offered another way as someone was asking the *EXACT* same thing the other day
In the Load event you can use

Me.cboGroup.DefaultValue = OpenArgs

which I will try next time I need to do this.
 
Thanks its working fine.

if i want to update two combo box on frmCreateAccount lets say

from frmAddnewAccount selected Option4 then "Liability"

AND second is "Bank Loans" to frmCreateAccount


frmCreateAccount
cboGroup = "Liability"
cboType = "Bank Loans"


Code:
If Me.Option4 = True Then
DoCmd.OpenForm "frmCreateAccount", acNormal, , , acFormAdd, acDialog, "Liability"
DoCmd.OpenForm "frmCreateAccount", acNormal, , , acFormAdd, acDialog, "Bank Loans"
End If

How can i do that?
 
Code:
DoCmd.OpenForm "frmCreateAccount", acNormal, , , acFormAdd, acDialog, "Liability;BankLoans"

Code:
Private Sub Form_Load()
 
 If Not Trim(Me.OpenArgs & " ") = "" Then
    Me.cboGroup = split(Me.OpenArgs,";")(0)
    me.cboType = split(Me.OpenArgs, ";")(1)
 End If

  Me.chk1.Value = False

End Sub
 
Thanks but its giving error subscript out of range and when i click end in debugging its showing correct records.

but each time i run its give this error, only for the single args arguments and not for double

Why this error any clue how to fix it.
 
Do you ever understand anything that is posted to help you?:banghead:

You asked for two parameters. MajP split them with a ;

If you only supply one parameter it is not going to work.:banghead:

On every post you make, you keep moving the goalposts. You state code that is posted does not work, yet I it works for everyone else.?

You have made over 200 posts and there is not one Thanks in your profile.:mad: despite all the help you have received here.?
 
If you clicked on debug it would highlight the individual error line which may have helped you identify the cause, which you have identified but in a more indirect route.

When you only pass one value the split function fails because it's looking for 2. Ensure a you pass a empty string or similar to avoid a invalid response.
 
Code:
If Not Trim(Me.OpenArgs & " ") = "" Then
    Me.cboGroup = split(Me.OpenArgs,";")(0)
    if ubound(split(Me.OpenArgs,";")) = 1 then
      me.cboType = split(Me.OpenArgs, ";")(1)
    end if 
End If

  Me.chk1.Value = False

End Sub
 
Gasman

Code:
Do you ever understand anything that is posted to help you?


I do understand and near to accomplish my two databases and will post here shortly for examples and a great tools for HR and Accounting departments.

Code:
On every post you make, you keep moving the goalposts. You state code that is posted does not work, yet I it works for everyone else.?

I don't give lot of things at same time, I give myself chance to solve something after getting the right path even after I am not able to complete than I mention it here, also what computer setting is for everybody may be that is not for me or different I am not wishing to tell it is not working while its working with others then there might be some network or previllage issue with computer settings or over network that i work on, that's common it can be not a big deal.

Code:
You have made over 200 posts and there is not one Thanks in your profile. despite all the help you have received here.?

I can understand your frustration, I do thank in every post reply when someone provide helping hands, but when I saw your reply in this post I surprise because I do thank then I search on the forum what exactly do you mean by thanks and I done it for my all posts who ever helped me, sorry for that because I was not aware of programitically thanks in forums.

Since I dont have access to computer now I will see the remaining programitically thankings on Sunday.

I will do extention to this post query once apply the MajP recent code.

My special thanks for my following forum friends who help me a lot.

Isladog you are great
MajP
June7
Plog
Uncle Gizmo

Please don't mind if I forgot to take anybody's name.
 
Last edited:
FYI,
Dialog forms can be very helpful because when I call this
Code:
DoCmd.OpenForm "frmCreateAccount", acNormal, , , acFormAdd, acDialog, "Liability;BankLoans"
the code in the calling form stops. It starts up again where you left off once the dialog form is closed.

However if the form is set as popup and modal it kind of acts the same except code execution does not stop in the calling form. This could allow you to control the pop up form from the called form, and make it potentially simpler. If acdialog set then you are stuck with passing openargs because code execution stopped in the calling form. If not you could do something simple like

Code:
DoCmd.OpenForm "frmCreateAccount", acNormal, , , acFormAdd
'since not acdialog code continues
forms!frmCreateAccount.cboGroup = "Liability"
Forms!frmCreateAccount.cboType = "BankLoans"
 

Users who are viewing this thread

Back
Top Bottom