Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 29th, 2006, 04:58 PM
Authorized User
 
Join Date: Feb 2006
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Filling a list box with WHERE clause

I am tring to fill a list box and was initally successfull until I put a WHERE clause in the SQL statement. Now when I try and run it I get an error that says:

"Either BOF or EOF is true, or the current record has been deleted. Requested Operation requires a current record.

I have verified that the variable, "sAuditor", is finding a match in the database. Here is my code.
///////////////////////////////////////////////////////////////////
Public Sub FillListAuditor()

   Dim rst As ADODB.Recordset
    Dim strList As String
    Dim strSQL As String

    Set m_cnn = CurrentProject.Connection

    sAuditor = cmbAuditor.Value

    strSQL = "SELECT RecordNumber, DateRecorded, RepName, AuditType, Auditor, AuditDate FROM Main " _
        & "INNER JOIN Reps ON Main.Rep = Reps.RepId WHERE Auditor = ' " & sAuditor & " ' ORDER BY DateRecorded DESC"

    Set rst = New ADODB.Recordset
    rst.Open strSQL, m_cnn, adOpenForwardOnly, adLockOptimistic, adCmdText

    strList = BuildStringAuditor(rst)
    Me.RecList.RowSource = strList
    rst.Close

End Sub

Private Function BuildStringAuditor(rst As ADODB.Recordset) As String
    Dim strReturn As String
    Dim varItems As Variant
    Dim x As Integer
    Dim y As Integer

    rst.MoveFirst

    varItems = rst.GetRows()
    For x = LBound(varItems, 2) To UBound(varItems, 2)
        For y = LBound(varItems, 1) To UBound(varItems, 1)
            strReturn = strReturn & varItems(y, x) & ";"
        Next y
    Next x
    BuildStringAuditor = strReturn
End Function
/////////////////////////////////////

Any help would be appreciated.

Thanks,
Scott
__________________
ScottP
 
Old March 31st, 2006, 12:32 PM
Authorized User
 
Join Date: Feb 2006
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. The single quote marks were in the wrong place.
Original code:
WHERE Auditor = ' " & sAuditor & " '

Corrected code:
WHERE Auditor = '" & sAuditor & "'

Scott





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling a combo box w/in datagridview kscase Visual Basic 2005 Basics 1 July 12th, 2007 07:26 AM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
filling a combo box from a data object allee_man Beginning VB 6 1 March 1st, 2005 08:08 AM
filling a combo box using an array tware VB Databases Basics 0 September 21st, 2004 08:40 AM
Filling in a list box with data from Access goplayoutside VB Databases Basics 7 April 21st, 2004 08:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.