Hello team,
What is the problem? When I fill out the control source for the combo box, I can not select anything from it.
Please see attached.
Regards,
tttttt
Issue with Combo Box
-
- BronzeLounger
- Posts: 1498
- Joined: 01 Mar 2015, 02:03
Issue with Combo Box
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Issue with Combo Box
The database that you attached contains a form with a single combo box. This form is bound to the table tbl_Hos. When you set the Control Source of the combo box to HosID, the primary key of tbl_Hos, the combo box will simply display the corresponding name. You can't select another item from the combo box since that would change the primary key of the table and cause the value to be duplicate. So there is no point in using a combo box on this form.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1498
- Joined: 01 Mar 2015, 02:03
Re: Issue with Combo Box
Hello Hans,
In the attached database, I have filled the row source for the combo box, I had a case which I originally created the post for, I was not able to add anything to the row source of the combo box - as you said it created duplicate primary keys/ or wants to fill out the pk of the table which has already existing values in it. I want to know what is the difference when I am able to add value to row source of combo box and sometimes I am not be able to add anything to row source of a combo box.
Post 202294:
Hans:" Having a combo box bound to a table does not make the form bound to that table. The Record Source of your main form should be blank."
Post 201893:
Hans:"The database that you attached contains a form with a single combo box. This form is bound to the table tbl_Hos. When you set the Control Source of the combo box to HosID, the primary key of tbl_Hos, the combo box will simply display the corresponding name. You can't select another item from the combo box since that would change the primary key of the table and cause the value to be duplicate. So there is no point in using a combo box on this form."
Does a combo box make a form bound to a table or not?
Regards,
tttttt
In the attached database, I have filled the row source for the combo box, I had a case which I originally created the post for, I was not able to add anything to the row source of the combo box - as you said it created duplicate primary keys/ or wants to fill out the pk of the table which has already existing values in it. I want to know what is the difference when I am able to add value to row source of combo box and sometimes I am not be able to add anything to row source of a combo box.
Post 202294:
Hans:" Having a combo box bound to a table does not make the form bound to that table. The Record Source of your main form should be blank."
Post 201893:
Hans:"The database that you attached contains a form with a single combo box. This form is bound to the table tbl_Hos. When you set the Control Source of the combo box to HosID, the primary key of tbl_Hos, the combo box will simply display the corresponding name. You can't select another item from the combo box since that would change the primary key of the table and cause the value to be duplicate. So there is no point in using a combo box on this form."
Does a combo box make a form bound to a table or not?
Regards,
tttttt
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Issue with Combo Box
In the attached version, I have changed the combo box in the Detail section of the form to a text box. This control is bound to the HosID field; it should not be used to select the hospital.
I have added an unbound combo box cboHos in the Form Header section. The Control Source of this combo box is empty (that's why it's called unbound). Its Row Source is a query based on the table that sorts the records by HosName.
I have added code in the After Update event of this combo box to jump to the record of the selected hospital:
I have also added a command button cmbNew to the form header. Clicking this button will jump to a new record; you can enter the name of a new hospital here.
Finally, to make sure that a new hospital is displayed in this combo box, I added an After Insert event procedure to the form:
I have added an unbound combo box cboHos in the Form Header section. The Control Source of this combo box is empty (that's why it's called unbound). Its Row Source is a query based on the table that sorts the records by HosName.
I have added code in the After Update event of this combo box to jump to the record of the selected hospital:
Code: Select all
Private Sub cboHos_AfterUpdate()
With Me.RecordsetClone
.FindFirst "HosID=" & Nz(Me.cboHos, 0)
If .NoMatch Then
Beep
Else
Me.Bookmark = .Bookmark
End If
End With
End Sub
Code: Select all
Private Sub cmbNew_Click()
On Error Resume Next
RunCommand acCmdRecordsGoToNew
If Err Then Beep
End Sub
Code: Select all
Private Sub Form_AfterInsert()
Me.cmbNew.Requery
End Sub
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1498
- Joined: 01 Mar 2015, 02:03
Re: Issue with Combo Box
Hans,
Thanks a lot for the response.
I have to study it thoroughly.
Regards,
tttttt
Thanks a lot for the response.
I have to study it thoroughly.
Regards,
tttttt