Results 1 to 7 of 7
  1. #1
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286

    Display RESULTS of Query into LISTBOX?

    Hello i have a form where a user enters a channelid into a textbox and then clicks a button. once the button is clicked, a query is ran where it looks at what channelid the user typed and displays a table based on that criteria.



    how do i get the table to be displayed into the listbox instead of having the table pop up? thanks!

    pic is attached

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by taimysho0 View Post
    Hello i have a form where a user enters a channelid into a textbox and then clicks a button. once the button is clicked, a query is ran where it looks at what channelid the user typed and displays a table based on that criteria.

    how do i get the table to be displayed into the listbox instead of having the table pop up? thanks!

    pic is attached
    Create a list box in the form. In the same button where the query is run, do the following

    Dim sSQL as string
    sSQL = "Select bla bla bla..." 'your sql for the query

    Me.YourListBox.Rowsource=sSQL 'assign the sql statement as the rowsource to the list box

  3. #3
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    hello, thanks so much for the help. the only thing is, it only returns ONE column from the table. how do i get it to show ALL the columns i need (i need about 6 columns to show); as well as displaying the headers? thanks

  4. #4
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    by the way, the column it is returning is just the channel id column (basically whatever ID the user typed into the textbox)

    pic attached

    here is my code:

    Private Sub btngo_Click()
    Dim sSQL As String
    sSQL = ("SELECT tblHHFRequest_tais.[Channel ID], tblHHFRequest_tais.[Date Requested], tblHHFRequest_tais.City, tblHHFRequest_tais.[Due Date], tblHHFRequest_tais.[LAN ID], tblHHFRequest_tais.[HHF Status], tblHHFRequest_tais.Notes, tblHHFRequest_tais.[Field Order #], tblHHFRequest_tais.Supervisor, tblHHFRequest_tais.[Crew Lead] FROM tblHHFRequest_tais WHERE (((tblHHFRequest_tais.[Channel ID])=[Forms]![frmChannelIDSearch]![txtChannelID].[value]));")
    'your sql for the query
    'assign the sql statement as the rowsource to the list box

    Dim stDocName As String

    stDocName = "qryChannelIDSearch"

    If Me.txtChannelID.Value = "" Then
    MsgBox ("ERROR:Invalid Channel ID!")
    Else
    Me.lstChannelID.RowSource = sSQL

    End If


    End Sub

  5. #5
    Join Date
    Nov 2011
    Location
    Hamilton, NZ
    Posts
    18
    try this

    Private Sub btngo_Click()
    Dim sSQL As String
    sSQL = ("SELECT tblHHFRequest_tais.[Channel ID], tblHHFRequest_tais.[Date Requested], tblHHFRequest_tais.City, tblHHFRequest_tais.[Due Date], tblHHFRequest_tais.[LAN ID], tblHHFRequest_tais.[HHF Status], tblHHFRequest_tais.Notes, tblHHFRequest_tais.[Field Order #], tblHHFRequest_tais.Supervisor, tblHHFRequest_tais.[Crew Lead] FROM tblHHFRequest_tais WHERE (((tblHHFRequest_tais.[Channel ID])=[Forms]![frmChannelIDSearch]![txtChannelID].[value]));")
    'your sql for the query
    'assign the sql statement as the rowsource to the list box

    Dim stDocName As String

    stDocName = "qryChannelIDSearch"

    If Me.txtChannelID.Value = "" Then
    MsgBox ("ERROR:Invalid Channel ID!")
    Else
    Me.lstChannelID.RowSource = sSQL
    Me.lstChannelID.ColumnCount = 6
    End If


    End Sub

  6. #6
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    nevermind, i was able to get it. the only thing is im not able to EDIT the fields? i need the user to be able to edit the fields. WIll a listbox not work?

    if it does not, i created a subform just in case, but would you know how to tie this to the button click so that it displays all the rows and columns in the subform based on the channel ID textbox input?

  7. #7
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by taimysho0 View Post
    nevermind, i was able to get it. the only thing is im not able to EDIT the fields? i need the user to be able to edit the fields. WIll a listbox not work?

    if it does not, i created a subform just in case, but would you know how to tie this to the button click so that it displays all the rows and columns in the subform based on the channel ID textbox input?
    No, you cannot edit records directly in a list box. You can create a edit form and from a click, have the edit form open where the user can edit the info. Upon saving the record, update the sql in the list box to display the current record

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

Similar Threads

  1. Replies: 2
    Last Post: 08-12-2011, 01:01 PM
  2. Replies: 1
    Last Post: 12-01-2010, 11:10 AM
  3. Form/Query Display Results Question
    By AcmeGearSteve in forum Access
    Replies: 5
    Last Post: 10-12-2010, 01:21 PM
  4. Display Query Results on a Form
    By P5C768 in forum Queries
    Replies: 5
    Last Post: 05-04-2010, 11:04 AM
  5. display query results in a form
    By P5C768 in forum Queries
    Replies: 3
    Last Post: 08-14-2009, 03:02 PM

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