ComboBox with Memory

A

Adrian

Hello!

I have this code, and I need that combobox "ELEGIR" not only shows to me the"ID" of the table dbo_Departamento, but also the field "Description" of the same table.

Please, Read the code carefully, since it works very well, but I dont know what I must add to him so that it shows in combobox that column!

--------------------------------------------------------------------------------

Private Sub Comando6_Click()
If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"
End Sub

Private Sub Elegir_AfterUpdate()
DoCmd.SetWarnings False
DoCmd.RunSQL "Insert into uDepartamento(uDepartamento)values(elegir)"

End Sub

Private Sub Elegir_GotFocus()
If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select id from dbo_Departamento"
Else
ELEGIR.RowSource = "select uDepartamento from a"
End If
End Sub

Private Sub Form_Current()
última = DLast("uDepartamento", "a")
End Sub
 
W

Wayne Morgan

Are you wanting both fields to show in the drop down or do you have both of them showing in the drop down and you want both to show after you've made a selection?

To get them to both show in the drop down, you need to set the Column Count property of the combo box to the total number of columns in the combo box. Set the Column Widths to a value larger than zero for the columns you want displayed and set them to zero for the columns you want to hide (if any). Both of these are on the Format tab. On the Data tab, set the Bound Column to the column that contains the value you want to use as the combo box's value. This is the value that will be stored in the form's table if the combo box's Control Source is bound to a field. The multiple columns will be filled by the Row Source in the same order that the fields are listed in the Row Source's query. To get more than one column, you would have more than one field returned by the query.

All fields whose column width is larger than zero will show in the drop down of a combo box, but only the first visible field will show in the textbox portion of the combo box. One way around this is to place a textbox next to the combo box and set the Control Source of the textbox to the column of the combo box that you want displayed.

Example:
=MyCombo.Column(1)

The index number in the Column() property is zero based, so 0 is the first column, 1 is the second, 2 is the third, etc.

--
Wayne Morgan
MS Access MVP


Hello!

I have this code, and I need that combobox "ELEGIR" not only shows to me the"ID" of the table dbo_Departamento, but also the field "Description" of the same table.

Please, Read the code carefully, since it works very well, but I dont know what I must add to him so that it shows in combobox that column!

------------------------------------------------------------------------------

Private Sub Comando6_Click()
If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"
End Sub

Private Sub Elegir_AfterUpdate()
DoCmd.SetWarnings False
DoCmd.RunSQL "Insert into uDepartamento(uDepartamento)values(elegir)"

End Sub

Private Sub Elegir_GotFocus()
If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select id from dbo_Departamento"
Else
ELEGIR.RowSource = "select uDepartamento from a"
End If
End Sub

Private Sub Form_Current()
última = DLast("uDepartamento", "a")
End Sub
 
A

Adrian

Hello, thanks for reply!

Your explanation Its OK!!! But my problem consists of which row source directly takes it from the code of Visual BASIC, not from of the properties of the ComboBox, therefore I do not know how to say to Access that shows to him, not only the column, but another field of the same table.

I hope understands to me.

Thanks in advance!


"Wayne Morgan" <[email protected]> escribió en el mensaje Are you wanting both fields to show in the drop down or do you have both of them showing in the drop down and you want both to show after you've made a selection?

To get them to both show in the drop down, you need to set the Column Count property of the combo box to the total number of columns in the combo box. Set the Column Widths to a value larger than zero for the columns you want displayed and set them to zero for the columns you want to hide (if any). Both of these are on the Format tab. On the Data tab, set the Bound Column to the column that contains the value you want to use as the combo box's value. This is the value that will be stored in the form's table if the combo box's Control Source is bound to a field. The multiple columns will be filled by the Row Source in the same order that the fields are listed in the Row Source's query. To get more than one column, you would have more than one field returned by the query.

All fields whose column width is larger than zero will show in the drop down of a combo box, but only the first visible field will show in the textbox portion of the combo box. One way around this is to place a textbox next to the combo box and set the Control Source of the textbox to the column of the combo box that you want displayed.

Example:
=MyCombo.Column(1)

The index number in the Column() property is zero based, so 0 is the first column, 1 is the second, 2 is the third, etc.

--
Wayne Morgan
MS Access MVP


Hello!

I have this code, and I need that combobox "ELEGIR" not only shows to me the"ID" of the table dbo_Departamento, but also the field "Description" of the same table.

Please, Read the code carefully, since it works very well, but I dont know what I must add to him so that it shows in combobox that column!

----------------------------------------------------------------------------

Private Sub Comando6_Click()
If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"
End Sub

Private Sub Elegir_AfterUpdate()
DoCmd.SetWarnings False
DoCmd.RunSQL "Insert into uDepartamento(uDepartamento)values(elegir)"

End Sub

Private Sub Elegir_GotFocus()
If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select id from dbo_Departamento"
Else
ELEGIR.RowSource = "select uDepartamento from a"
End If
End Sub

Private Sub Form_Current()
última = DLast("uDepartamento", "a")
End Sub
 
W

Wayne Morgan

To get more than one column in the combo box you need to, 1) Set the combo box's Column Count property to the number of columns, 2) Pick which column will be the Bound Column, 3) decide if you want to hide any of the columns by setting the Column Widths property, 4) Use a query (Select statement) for the Row Source that returns more than one field.

For example, you are currently using ELEGIR.RowSource = "select uDepartamento from a" as the Row Source. This is returning only one field "uDepartamento" from the table "a". Therefore, you will get only one column. If you want more than one column, you'll need to return more than one field. (i.e. ELEGIR.RowSource = "select uDepartamento, Field2 from a"). This now will give you two columns in the combo box. One for uDepartamento and one for Field2.

--
Wayne Morgan
MS Access MVP


Hello, thanks for reply!

Your explanation Its OK!!! But my problem consists of which row source directly takes it from the code of Visual BASIC, not from of the properties of the ComboBox, therefore I do not know how to say to Access that shows to him, not only the column, but another field of the same table.
 
U

Utopian

Wayne!! thanks so much for your help!!!!! your explanation OPEN MY MIND!!

I can resolve my problem!!! Even I "invent" this portion of code and work OK!!!

ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

....but, still I have left to solve two things more:

1 Which the last value of "descripcion" also is shown by defect in the Combobox and not only the "ID"

2-That this value is visible in the next beginning of the application, without having to unfold the ComboBox.

Hugs from Argentina!! and sorry for my english.

Adrian.-

--------------------------------------------------------------------------------

"Wayne Morgan" <[email protected]> escribió en el mensaje To get more than one column in the combo box you need to, 1) Set the combo box's Column Count property to the number of columns, 2) Pick which column will be the Bound Column, 3) decide if you want to hide any of the columns by setting the Column Widths property, 4) Use a query (Select statement) for the Row Source that returns more than one field.

For example, you are currently using ELEGIR.RowSource = "select uDepartamento from a" as the Row Source. This is returning only one field "uDepartamento" from the table "a". Therefore, you will get only one column. If you want more than one column, you'll need to return more than one field. (i.e. ELEGIR.RowSource = "select uDepartamento, Field2 from a"). This now will give you two columns in the combo box. One for uDepartamento and one for Field2.

--
Wayne Morgan
MS Access MVP


Hello, thanks for reply!

Your explanation Its OK!!! But my problem consists of which row source directly takes it from the code of Visual BASIC, not from of the properties of the ComboBox, therefore I do not know how to say to Access that shows to him, not only the column, but another field of the same table.
 
W

Wayne Morgan

Do you want both ID AND Descripcion to show in the combo box after you make a selection? If so, you need to go back to my previous posts. The combo box won't do this. It will only show the FIRST visible column after the selection. You could place a calculated textbox next to the combo box to show the other column. If you don't want ID to show at all, not even in the drop down, then set the width of that column to zero.

To get the value to show the next time you come to the record, the combo box needs to be bound to a field in the form's Record Source, just as you would a textbox. Set the Control Source of the combo box to a field in the form's Record Source. The value that will be stored is the value from the combo box's Bound Column. This column should have unique values for each row.

--
Wayne Morgan
MS Access MVP


Wayne!! thanks so much for your help!!!!! your explanation OPEN MY MIND!!

I can resolve my problem!!! Even I "invent" this portion of code and work OK!!!

ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

...but, still I have left to solve two things more:

1 Which the last value of "descripcion" also is shown by defect in the Combobox and not only the "ID"

2-That this value is visible in the next beginning of the application, without having to unfold the ComboBox.

Hugs from Argentina!! and sorry for my english.
 
U

Utopian

Thanks so much Wayne Morgan!

Last question, I promise!

Help to me, know sintaxis for this:

1-How to add the Field uDescripcion to this lines of code?:

DoCmd.RunSQL "Insert into uDepartamento(uDepartamento)values(elegir)"

--------------------------------------------------------------------------------

ELEGIR.RowSource = "select uDepartamento from A"

--------------------------------------------------------------------------------

última = DLast("uDepartamento", "A")

--------------------------------------------------------------------------------

Note: "A" is a Query and UDepartamento anda UDescripcion are Fields into "A" and into the Table UDepartamento .....

Thanks!!

--------------------------------------------------------------------------------


"Wayne Morgan" <[email protected]> escribió en el mensaje Do you want both ID AND Descripcion to show in the combo box after you make a selection? If so, you need to go back to my previous posts. The combo box won't do this. It will only show the FIRST visible column after the selection. You could place a calculated textbox next to the combo box to show the other column. If you don't want ID to show at all, not even in the drop down, then set the width of that column to zero.

To get the value to show the next time you come to the record, the combo box needs to be bound to a field in the form's Record Source, just as you would a textbox. Set the Control Source of the combo box to a field in the form's Record Source. The value that will be stored is the value from the combo box's Bound Column. This column should have unique values for each row.

--
Wayne Morgan
MS Access MVP


Wayne!! thanks so much for your help!!!!! your explanation OPEN MY MIND!!

I can resolve my problem!!! Even I "invent" this portion of code and work OK!!!

ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

...but, still I have left to solve two things more:

1 Which the last value of "descripcion" also is shown by defect in the Combobox and not only the "ID"

2-That this value is visible in the next beginning of the application, without having to unfold the ComboBox.

Hugs from Argentina!! and sorry for my english.
 
W

Wayne Morgan

Where do you want it added, to the Row Source? If so, try:

ELEGIR.RowSource = "select uDepartamento, uDescripcion from A"

This will place uDepartamento in the first column and uDescripcion in the second column. Judging by your RunSQL statement, you want the "value" of the combo box to be the first column, so the Bound Column should be 1.

Also, I believe that this line will cause you problems:

DoCmd.RunSQL "Insert into uDepartamento(uDepartamento)values(elegir)"

Are you trying to put the Value of the combo box Elegir into the field uDepartamento in the uDepartamento table? If so, you need to make one of two changes.

1) You can concatenate in the value of Elegir.

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento) values (" Me.elegir & ")"

Or
2) You can give the full path to Elegir.

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento) values (Forms!FormName!elegir)"

--
Wayne Morgan
MS Access MVP


Thanks so much Wayne Morgan!

Last question, I promise!

Help to me, know sintaxis for this:

1-How to add the Field uDescripcion to this lines of code?:

DoCmd.RunSQL "Insert into uDepartamento(uDepartamento)values(elegir)"
 
Top