{"id":1171,"date":"2022-08-30T15:13:34","date_gmt":"2022-08-30T15:13:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/ms-access-combobox-not-allowing-me-to-select-an-item-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:34","modified_gmt":"2022-08-30T15:13:34","slug":"ms-access-combobox-not-allowing-me-to-select-an-item-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ms-access-combobox-not-allowing-me-to-select-an-item-collection-of-common-programming-errors\/","title":{"rendered":"MS Access &#8211; ComboBox not allowing me to select an item-Collection of common programming errors"},"content":{"rendered":"<p>new to Access here and already spent a lot of time trying to solve this problem, so here the background:<\/p>\n<p>Note: already had a look at this: ComboBox won&#8217;t allow me to select an item, but didn&#8217;t provide the answers I needed.<\/p>\n<p>I have a database that allows a person to input and store customer details via forms, and currently I have 3 tables with the following relationships:<\/p>\n<p><strong>Customer<\/strong> &#8211; CustomerID (PK) &#8211; FirstName &#8211; LastName<\/p>\n<p><strong>Process<\/strong> &#8211; ProcessID (PK) &#8211; Detail &#8211; PartsUse &#8211;<\/p>\n<p><strong>Job<\/strong> &#8211; JobID (PK) &#8211; CustomerID (FK) &#8211; ProcessID (FK) &#8211; MachineDetail &#8211;<\/p>\n<p>Customer has a 1-M relation with Job, but by extension (not sure why) Process also has a 1-M relationship with Job also. So the aim here is that a customer can have many jobs, and a job should only have one process (will need to fix that up later).<\/p>\n<p>Now here&#8217;s my code to bind the ComboBox in my NewJob form &#8211; its objective is to populate the ComboBox with all the names of the customer when the form opens, and only allowing the user to enter the job details after a customer has been selected:<\/p>\n<pre><code>Private Sub Form_Open(Cancel As Integer)\n\n    Dim db As Database\n    Dim recordSet As DAO.recordSet\n    Dim sql As String\n\n    sql = \"SELECT [Customer].[CustomerID], [Customer].[FirstName] &amp; [Customer].[LastName] FROM Customer ORDER BY [CustomerID];\"\n\n    'clear all fields\n    ClearJobFormFields\n\n    'disable all controls until a customer is selected\n    DisableJobFormControls\n\n    With cmbCustomer\n        .ControlSource = \"Customer\"\n        .RowSource = sql\n        .ColumnCount = 2\n        .ColumnWidths = \"1cm; 3cm\"\n        .BoundColumn = 0\n    End With\n\n    cmbCustomer.ControlSource = \"Customer\"\n    cmbCustomer.RowSource = sql\n\nEnd Sub\n<\/code><\/pre>\n<p>Just to note, each form is independent &#8211; I am not using subforms. The form this is on (NewJob) DOES have <code>AllowEdit<\/code> set to yes, and the form has no <code>RecordSource<\/code> bound to it.<\/p>\n<p>The ComboBox DOES populate properly, but everytime I try to select an item, I get the error: &#8220;control cannot be edited it&#8217;s bound to unknown field Customer&#8221;.<\/p>\n<p>And that&#8217;s all there is to it. Sorry if this is a common \/ easy-to-solve problem, but its been bugging me for days.<\/p>\n<ol>\n<li>\n<p>If your form has no Recordsource, your control shouldn&#8217;t (can&#8217;t) have a Controlsource. If you go to properties of the form in design mode, you will see that Customer is not a valid choice at the Controlsource property. Why don&#8217;t you have a Recordsource. Isn&#8217;t the objective of the form to input Job data?<\/p>\n<\/li>\n<li>\n<p>As you are setting the rowsource property via VBA, you should leave this as an unbond control and scrap:<\/p>\n<pre><code>cmbCustomer.ControlSource = \"Customer\"\n<\/code><\/pre>\n<p>Your open form sub should be more like this:<\/p>\n<pre><code>Private Sub Form_Open(Cancel As Integer)\n\nDim db As Database\nDim recordSet As DAO.recordSet\nDim sql As String\n\n    sql = \"SELECT [Customer].[CustomerID], [Customer].[FirstName] &amp; [Customer].[LastName] FROM Customer ORDER BY [CustomerID];\"\n\n    'clear all fields\n    ClearJobFormFields\n\n    'disable all controls until a customer is selected\n    DisableJobFormControls\n\n    With cmbCustomer\n        .RowSource = sql\n        .ColumnCount = 2\n        .ColumnWidths = \"1cm; 3cm\"\n        .BoundColumn = 0\n    End With\n\nEnd Sub\n<\/code><\/pre>\n<p>And then you can use the after update event of this combobox to determine whether or not to enable the job details fields:<\/p>\n<pre><code>Private Sub cmbCustomer_AfterUpdate()\n\n    'Check it's populated and set fields as necessary\n    If cmbCustomer &amp; \"\" = \"\" Then\n        txtJobDetails.Enabled = 0 'Change this fieldname as required\n    Else\n        txtJobDetails.Enabled = -1\n    End If\n\nEnd Sub\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:34:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>new to Access here and already spent a lot of time trying to solve this problem, so here the background: Note: already had a look at this: ComboBox won&#8217;t allow me to select an item, but didn&#8217;t provide the answers I needed. I have a database that allows a person to input and store customer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1171","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1171"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1171\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}