X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> List Box Add Item, Access 2016    
post Jul 15 2019, 04:16 AM

Posts: 182
Joined: 10-August 17

Hi UA Nation!

I have a big headache with my Combobox selection as mentioned below:

I have a Combobox bound with the table as below:

Private Sub cboDept_Enter()
    With txtProductCode
        .RowSource = "SELECT * FROM tblProductMaster"
        .ColumnCount = 8
        .BoundColumn = 1
        .ColumnWidths = 0";0";0";0";0";0";0";1"
    End With
End Sub

1. But when I am Selecting I can't select the different code with the same prefix value Ex. If I select 501W I can't select 501A but only can select 501W. Please see 1.PNG
2. When I click the Add to Production the value 50 only adding in the list box, not the 501W. Please See 2.PNG and below is the code I have used for this add function
Private Sub btnSchedule_Click()
Dim D As String
    Dim p1, p2, p3, p4
    If Len(txtDate & vbNullString) = 0 Then
        MsgBox "Please Enter Production Date", vbInformation, "Information"
        Exit Sub
    End If
    If Len(Me.txtProductCode & vbNullString) = 0 Then
        MsgBox "Please Enter Product Code", vbInformation, "Information"
        Exit Sub
    End If
    If Len(txtQty & vbNullString) = 0 Then
        MsgBox "Please Enter Order Planned Qty", vbInformation, "Information"
        Exit Sub
    End If

      If Len(txtMC & vbNullString) = 0 Then
        MsgBox "Please Choose Machine No.", vbInformation, "Information"
        Exit Sub
     End If
    p1 = "'" & txtDate.Value & "'"
    p2 = "'" & txtProductCode & "'"
    p3 = "'" & txtQty.Value & "'"
    p4 = "'" & txtMC.Value & "'"

    D = p1 & ";" & p2 & ";" & p3 & ";" & p4 & ""
    listBox1.AddItem D
    btnSave.Enabled = True
    'txtProductCode = ""
    'txtQty = ""
    'txtMC = ""
End Sub

Please help me where went wrong BIG THANKS!

Attached File(s)
Attached File  1.PNG ( 9.75K )Number of downloads: 0
Attached File  2.PNG ( 8.55K )Number of downloads: 0
Go to the top of the page
post Jul 15 2019, 04:44 AM

Posts: 741
Joined: 25-January 16

It uses 50 because that is the value of the combobox.

Why do you need to save items to listbox? Why not just do data entry to record?

If you want to provide db for analysis, follow instructions at bottom of my post.

Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
post Jul 15 2019, 05:36 AM

Posts: 182
Joined: 10-August 17

Hi June7,

The intention of using the list box is to double-check the data entry before uploading, but I found my fault that I have to call the bound column as per the Combobox data column here just I called 1 instead 8. anyway thanks for your response
Go to the top of the page
post Jul 15 2019, 06:26 AM

UA Admin
Posts: 35,544
Joined: 20-June 02
From: Newcastle, WA

I believe it would have helped to see the table in the first post, because it appears that you didn't bind the combo box to the PRIMARY Key of that table initially. In your last post, you indicate that it does now work as intended because you changed from "column 1" to "column 8"

That suggests the field in column 8 contains either the primary key or it is a unique value that allows Access to recognize individual records.

My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    25th August 2019 - 10:30 AM