Results 1 to 15 of 15
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    List Selection (A2k)

    On a main form I have a text which has been populated from a pop up list of another form.

    If I want to change that selection, how do I open the popup with the item selected. ie:

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmPostToList"
    stLinkCriteria = "lstPostTo.ItemData=" & "'" & Me![txtPostTo] & "'"
    If not isNull(txtPostTo) then
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Else
    DoCmd.OpenForm stDocName
    End If

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Selection (A2k)

    Is the lstPostTo list box bound to a field?

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    Hans

    lstPostTo:

    Name - lstPostTo
    Control Source -
    Row Source Type - Table/Query
    RowSource - SELECT tblPostTo.Code, tblPostTo.Assessor .................................................. ..............
    Bound Column - 1 ..................

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Selection (A2k)

    Hi Dave,

    If the list box is unbound, you can't set its value by passing a WhereCondition argument to OpenForm. Instead, you must pass it in the OpenArgs argument, and use code in the OnLoad event of the popup form to set the value of the list box to the value in OpenArgs.

    I'll keep on nagging you with questions: to which column in the list box does the txtPostTo text box in the calling form correspond?

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    Hans
    I've still got to get to grips with "OpenArgs" although I understand it a little.

    frmDetails Holds txtPostTo
    This related to lstPostTo.Column(1),,,,,,,,,,,,, frmPostToList is the holding form for the list.

    I tried to solve it myself before answering this post :-

    """" Pop Up """"""
    Private Sub Form_Open(Cancel As Integer)
    Dim Selection As String
    Selection = Me.LstPostTo.Column(1)
    End Sub


    """"" Main Form """"""""

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmPostToList"
    stLinkCriteria = "lstPostTo.itemdata=" & "'" & Me![txtPostTo] & "'"
    If Not IsNull(txtPostTo) Then
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , openargs:=Me.txtPostTo
    Else
    DoCmd.OpenForm stDocName
    End If

    Not right but at least I attempted it ,,,

    Dave
    Attached Images Attached Images

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Selection (A2k)

    Gotta run now. I'll get back later.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    Is it lunch time already ??

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: List Selection (A2k)

    Dave,

    Try something like this, assuming that part of your goal is to set the listbox to the value passed.

    Private Sub Form_Open(Cancel As Integer)
    Dim Selection As String

    Selection = Nz(Me.,OpenArgs)
    If Selection <> "" Then
    Me.LstPostTo = Selection
    End If
    End Sub
    Charlotte

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    Charlotte, sorry it didn't work. (Thanks)
    I thought it was the typo, but rectifying that didn't prove fruitful.

    With my original, I don't think I am far off, A parameter is popping up asking for:

    lstPostTo.itemdata

    If I just enter thru it, the form opens without a selection.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Selection (A2k)

    Dave, I think you're not using the right field (plus you can't refer to ItemData this way). The first field in the row source of the list box is tblPostTo.Code, and you're trying to feed it a name from txtPostTo such as "H S Calvert". Does the code field contain names? (I doubt it)

  11. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    I thought the penny had dropped, but on stepping thru, "stLinkCriteria, Openargs:=me.txtPostTo & itemData" all returned the correct argument !!

    I've probably got the basic principals mixed up here some where.

    I'll have another play and see what I come up with.

    Thanks anyway.
    Attached Images Attached Images

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Selection (A2k)

    What does the screenshot display?

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    Hans
    Its the query view of the list, showing column(1) as the field to set criteria from forms!frmDetails!txtPostTo.

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Selection (A2k)

    In order to show "H S Calvert" in the list, you will have to set its value to the corresponding code, "CAL001". So if txtPostTo contains "H S Calvert", you can't use that, you must get the code and pass that as OpenArgs. You can then set the value of the list box to OpenArgs.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Selection (A2k)

    Yes I see what you mean. I'll play with it later, and it's nearly Friday Pub Night <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Have a good weekend .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •