Results 1 to 7 of 7
  1. #1
    englisap is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2011
    Posts
    9

    obtain value from listbox

    in the following code i try to obtain the value in the first column of the selected row it works in different code elsewhere in the form but for some reason it returns the same value in this case please help i have spent the last 10 hours trying different methods to fix this.



    Code:
    Private Sub CallSearchResults_Click()
    DoCmd.OpenForm "Call Info"
    Forms![Call Info]![fnameTXT].Value = Forms![Customer Support Department]![fnametb].Value
    Forms![Call Info]![lnameTXT].Value = Forms![Customer Support Department]![lnametb].Value
    Forms![Call Info]![phonetxt].Value = Forms![Customer Support Department]![CallSearchResults].Column(3)
    Forms![Call Info]![DateCallTXT].Value = Forms![Customer Support Department]![CallSearchResults].Column(1)
    Forms![Call Info]![TimeCallTXT].Value = Forms![Customer Support Department]![CallSearchResults].Column(2)
    Dim ID As Integer
    ID = [CallSearchResults].[Column](0)
    Forms![Call Info]![DepartmentTXT].Value = DLookup("[Department]", "[Call Search]", "ID = [ID]")
    Forms![Call Info]![Remarkstxt].Value = DLookup("[Remarks]", "[Call Search]", "ID = [ID]")
    End Sub

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what line is the problem?

  3. #3
    englisap is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2011
    Posts
    9
    the ID = CallSearchResults.column(0) line no matter what selection i choose it has the same value

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by englisap View Post
    the ID = CallSearchResults.column(0) line no matter what selection i choose it has the same value
    well first of all, that is not the syntax you posted. this is:
    Code:
    ID = [CallSearchResults].[Column](0)
    That's more in line with javascript syntax. IMO, it should be:
    Code:
    ID = CallSearchResults.Column(0)
    try that first. and as a practice, you should add "me." in front of those controls, although it's not necessary.

  5. #5
    englisap is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2011
    Posts
    9
    after making your changes it still is not working the id seems to be the same value every time no matter what is selected although other values in the list-box change when the selection changes. at least the display changes the way i want it to so it seems like the column 0 is only giving me the top row or lowest number

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    well do you realize that the code is in the same procedure as the opening of that actual form?

    in other words, what I'm saying is that your form is opening AND your trying to grab a box value from a listbox ON that form in the same procedure. It doesn't make sense to me HOW you are able to change the value that is selected in the listbox anyway.

    technically, when a form opens, listbox values shouldn't be selected. care to explain how you are performing these manipulations for testing purposes?

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try this:

    Code:
    Private Sub CallSearchResults_Click()
       DoCmd.OpenForm "Call Info"
       Forms![Call Info]![fnameTXT] = Forms![Customer Support Department]![fnametb]
       Forms![Call Info]![lnameTXT] = Forms![Customer Support Department]![lnametb]
       Forms![Call Info]![phonetxt] = Forms![Customer Support Department]![CallSearchResults].Column(3)
       Forms![Call Info]![DateCallTXT] = Forms![Customer Support Department]![CallSearchResults].Column(1)
       Forms![Call Info]![TimeCallTXT] = Forms![Customer Support Department]![CallSearchResults].Column(2)
       Dim intID As Integer
       intID = Forms![Customer Support Department]![CallSearchResults].Column(0)
       Forms![Call Info]![DepartmentTXT] = DLookup("[Department]", "[Call Search]", "ID = " & intID)
       Forms![Call Info]![Remarkstxt] = DLookup("[Remarks]", "[Call Search]", "ID = " & intID)
    End Sub
    Look at the DLOOKUP syntax....

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

Similar Threads

  1. Obtain the MAX values on a monthly basis
    By rajmns in forum Queries
    Replies: 1
    Last Post: 12-14-2010, 02:32 PM
  2. INSERT INTO with listbox
    By TheShabz in forum Programming
    Replies: 6
    Last Post: 11-30-2010, 12:19 PM
  3. Horizontal listbox - ?
    By bane in forum Forms
    Replies: 3
    Last Post: 04-20-2010, 06:48 PM
  4. Replies: 3
    Last Post: 04-14-2010, 10:00 AM
  5. Obtain data from another table
    By Suzied in forum Database Design
    Replies: 0
    Last Post: 03-23-2010, 11:52 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