Results 1 to 6 of 6
  1. #1
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250

    Trying to edit CBO value in a continuous form with VBA

    Hello,



    I have a database where I store products and every unit with its serial number.

    I am trying to create a system for repairs evidence.

    The idea is that I enter the serial number into one combo box and the product name appears in another one. I have the exact same functionality working well and I copied it. That's why I got confused because it's working well in one application and it doesn't work properly in another one.

    This is the data entry form for adding new orders where it works like I want to:
    Click image for larger version. 

Name:	db8.PNG 
Views:	18 
Size:	3.9 KB 
ID:	31695

    When serial number is updated, this VBA code runs:
    Code:
        If DCount("[SerialNumber]", "qryTransakceALL", "[SerialNumber] = [cboSerialNumber]") > 0 Then
            ProduktID = DLookup("[PKProduktID]", "qryTransakceALL", "[SerialNumber] = [cboSerialNumber]")
            cboFKProduktID.Value = ProduktID
            txtCena.SetFocus
        End If
    It's working well.

    The repair system is different because the product name isn't stored in the corresponding table. I just want to display it as an additional information. I tried this:
    Code:
        If DCount("[PKDetailObjednavkyID]", "qryTransakceALL", "[PKDetailObjednavkyID] = [cboSerialNumber]") > 0 Then
            ProductName = DLookup("[PKProduktID]", "qryTransakceALL", "[PKDetailObjednavkyID] = [cboSerialNumber]")
            Me.cboProductName.Value = ProductName
            txtNakladyNaOpravu.SetFocus
        Else
            MsgBox ("Zadané výrobní číslo neexistuje.")
            Me.Undo
        End If
    The problem is that when I change one serial number, all the product names fields in the continuous form get changed, now just the record that I want.

    Like in these pictures... I only changed the first serial number but it changed all the product types in all the records.

    Click image for larger version. 

Name:	db11.PNG 
Views:	17 
Size:	7.9 KB 
ID:	31698Click image for larger version. 

Name:	db12.PNG 
Views:	17 
Size:	7.1 KB 
ID:	31699

    Any ideas why?

    Thank you,
    Tomas
    Attached Thumbnails Attached Thumbnails db9.PNG   db10.PNG  

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It is because it is an unbound field, that is what happens.

  3. #3
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Quote Originally Posted by aytee111 View Post
    It is because it is an unbound field, that is what happens.
    Thanks. Yeah that makes sense. Any ideas how to work around this?

    The table where I store individual products repairs actually is a junction table between Order Details (I get serial number from here) and Repair Orders (which can constist of multiple products being repaired).

    The junction table itself has a connection to Order Details and Repair Orders primary keys and I store malfunction description and cost of the repair. How should I proceed when I want to display product name based on serial number? To what should I bound the text box?

    Thanks.
    Tomas

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You could try joining the table in to the record source for the form and then make it a bound field. This has to be a straight join otherwise you won't be able to update.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Include the product name as a column in the combobox RowSource - column can be hidden. Then expression in textbox can reference the column by index. Index starts at 0 so if product name is in column 2 its index is 1: =cboProductName.Column(1)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Thomasso is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Quote Originally Posted by June7 View Post
    Include the product name as a column in the combobox RowSource - column can be hidden. Then expression in textbox can reference the column by index. Index starts at 0 so if product name is in column 2 its index is 1: =cboProductName.Column(1)
    That worked, thanks! :-)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-09-2016, 05:54 PM
  2. Replies: 3
    Last Post: 11-03-2016, 06:11 AM
  3. Continuous search form won't open selected record in view form.
    By IncidentalProgrammer in forum Programming
    Replies: 20
    Last Post: 03-24-2015, 02:53 PM
  4. Replies: 2
    Last Post: 01-01-2014, 02:10 PM
  5. Replies: 1
    Last Post: 05-31-2013, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums