Results 1 to 8 of 8
  1. #1
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11

    Copy the value of a particular column of a combobox

    good morning
    in my database I have a form and a report (both read a query).
    Into the form I have a combobox with 5 columns, which displays the first column but uses the value of the second. This second value (numeric type) is used to filter the mask.
    example data of the combobox:
    Name; num;city;zipcode;nation
    Anthony; 1;Rome;00100;Italy
    Mary;2;Turin;10100;Italy
    So if I choose the Antony item the value of the combobox displays Antony and my filter query gets the value 1.
    Instead, I need to use into my report a label control where to display the value of the first column of the combobox present in the form, therefore it must display Antony.
    example:
    mask name = mAA
    Report name = RptAA
    mask combobox name mAA = cmbx1
    mask label name mAA = Lblcmbx1
    report label name RptAA = Lbl1
    Here are my instructions that currently return 1 and not Antony
    mAA)
    Code:
    Private Sub cmbx1 _AfterUpdate()
    me. Lblcmbx1 .caption =  me. cmbx1 Column(1, Me.cmbx1.Items)  
    end sub

    (RptAA)


    Code:
    Private Sub Form_load()
    me. Lbl1.caption = Forms!mAA! Lblcmbx1 .caption
    end sub
    thank you for the clarification

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    combo and list box column is zero based, so second column is 1. Perhaps that is your issue.
    Usually, first column is the autonumber id of a record - not the second column. I don't know if your 1 and 2 values are record id's or not, but your setup looks a bit unusual.

    EDIT - what you show will work in code but not in a query. It's a bit more difficult to use the column value in a query. Then again, you shouldn't have to if this was the other way around.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    Name should not be used as a fieldname as it is a reserved word in Access.
    I would suggest you rename the field to "Firstname"

    The normal configuration of a Combobox is as follows:

    Auronumber:FirstName: city: zipcode: nation
    1 Anthony;Rome;00100;Italy

    When you make the selection of Anthony on the Form then the Autonumber is stored.

    In the Report which is based on a Query you would add the value of Firstname from the table that contains the Firstname field.

    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  4. #4
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    Solved!

    I've forgot that the combo column and the list box column are zero-based.

    here is my code

    Code:
     Dim MyCbox As Integer: MyCbox = Me.Cmbx1.Value
    
    Me.Lblcmbx1.Caption = Me.Cmbx1.Column(0, Me.Cmbx1.Value = MyCbox)
    Thanks for the two clarifications

  5. #5
    MF_PA is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2024
    Location
    Italy
    Posts
    11
    thanks , but it was only an example and the real fieldname was another one .

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I don't see why you need to specify the row option?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    257
    Maybe it's best if you delve deeper into how to use a combo box.
    https://learn.microsoft.com/en-us/office/vba/api/access.combobox

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I presume white icon in post 5 image is the "New" button, which was clicked then the db window opened? I suspect that button would not move the window, just open it?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 14
    Last Post: 04-02-2022, 10:42 AM
  2. Replies: 5
    Last Post: 03-09-2020, 10:10 AM
  3. Replies: 3
    Last Post: 03-02-2015, 09:50 AM
  4. Replies: 1
    Last Post: 01-16-2015, 09:28 AM
  5. How do I copy all the data from a Column
    By winterh in forum Queries
    Replies: 5
    Last Post: 04-18-2012, 08:13 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