Results 1 to 7 of 7
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    select a combbox column for use as a variable

    Hi



    I have now thanks to the forum worked out why my tempvars are not working.

    I have a form with two combo boxes one selects the parish, the other the church using the code

    Code:
    SELECT tbl_Included_Church.ChurchID, tbl_Included_Church.Church, tbl_Included_Church.fk_ParishID
    FROM tbl_Included_Church
    WHERE (((tbl_Included_Church.fk_ParishID)=[Forms]![frm_OpeningForm]![CboParish]));
    to only show churches which are related tothat parish.

    the search button uses this code

    Code:
    Private Sub btnSearch_Click()
    TempVars.Add "varParish", Me.cboParish.Value
        TempVars.Add "varChurch", Me.cboChurch.Value
        DoCmd.Close
        DoCmd.OpenForm FormName:="frm_Home"
    End Sub
    The two combo boxes have two colums, one containg the id, the other the "text Value"

    so in my properties I have

    column count 2

    column width 0cm 3cm

    I now realise the variable is being set to column 1 ie the id rather than the value

    Would appreciate a fix

    thanks

    Ian

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You can't CLOSE the form and continue running code. Once the form closes, the code vanishes with it.
    do all events ,THEN close the form.

  3. #3
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    Thought I was doing all code before closing.

    However I do accept you know much more than I do.

    I did alter the code to carry out everything before closing the form but it still sets the variables to the first column in the table which is an id. So the temp var is 1 or 2 or 3 whereas want column 2 to be the variable ie. Allerton Church, St Marys or St Barnabys.

    Though about re ordering the table and dragging my column to to the column 1 position but is this good practice ?

    cheers

    Ian

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    This will give you the second column:

    TempVars.Add "varChurch", Me.cboChurch.Columns(1)

    Columns(1) is not a typo - the column references are zero-based (the first column is Column(0).

  5. #5
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    thanks for the info and I'm sure you are correct except that when I use the sugested code

    Code:
    Private Sub btnSearch_Click()
    TempVars.Add "varParish", Me.cboParish.Columns(1)
        TempVars.Add "varChurch", Me.cboChurch.Columns(1)
        DoCmd.Close
        DoCmd.OpenForm FormName:="frm_Home"
    End Sub
    The error is shown compile error

    method or data member not found

    and the .columns(1) is highlighted.

    The cbo box is set to column count 2 and the width is set to 0cm,3cm

    Now at a complete loss

    cheers

    Ian

  6. #6
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    Sorted thanks to everyone, I deleted the s from the end of columns and its all working

    cheers

    Ian

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Oops, sorry - my mistake. Glad you got it working.

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

Similar Threads

  1. Sql SELECT to variable
    By NejcZ in forum Programming
    Replies: 4
    Last Post: 10-04-2014, 01:19 AM
  2. Combbox / Filter Question
    By 82280zx in forum Programming
    Replies: 1
    Last Post: 03-16-2014, 04:07 PM
  3. Replies: 1
    Last Post: 03-14-2011, 10:04 AM
  4. Set column name with variable
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 01-28-2011, 12:57 PM
  5. SELECT INTO variable table name
    By Ian P in forum Queries
    Replies: 2
    Last Post: 05-29-2010, 12:49 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