ca1358
asked on
Excel Query VBA-When nothing is found-
This is Excel VBA
I have this piece of code, when I run this- the second query
'////20 year WAVG
Currently there is no record for this result, so I get an error
‘Either BOF or EOF is true, or the current record has been deleted.
Request operation requires a current record. “
I don’t know what to put to get by this.
Any help would greatly be appreciated.
Public Sub OpenADO()
Dim dbpath As String
Dim Src As String
Dim Connection As ADODB.Connection
Dim Col As Integer
Dim Recordset As ADODB.Recordset
Dim A1 As Range
'Without Password
dbpath = "C:\Documents and Settings\n574824\Databases \SRP\SRPtw o.mdb"
Set conn = New ADODB.Connection
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open dbpath
End With
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '
'////30 year WAVG
' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT [Expr1] " '<--- space added to
Src = Src & "FROM WA "
Src = Src & "WHERE ([LoanTerm] = '30' ) And [CompanyID] = " & TradeLimit.ComboBox1.Value
.Open source:=Src, ActiveConnection:=conn
'Write the recordset
Sheet9.Range("L10").Value = .Fields(0)
End With
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' ''
'////20 year WAVG
' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT [Expr1] " '<--- space added to
Src = Src & "FROM WA "
Src = Src & "WHERE ([LoanTerm] = '20' ) And [CompanyID] = " & TradeLimit.ComboBox1.Value
.Open source:=Src, ActiveConnection:=conn
End With
Set Recordset = Nothing
conn.Close
Set conn = Nothing
End Sub
I have this piece of code, when I run this- the second query
'////20 year WAVG
Currently there is no record for this result, so I get an error
‘Either BOF or EOF is true, or the current record has been deleted.
Request operation requires a current record. “
I don’t know what to put to get by this.
Any help would greatly be appreciated.
Public Sub OpenADO()
Dim dbpath As String
Dim Src As String
Dim Connection As ADODB.Connection
Dim Col As Integer
Dim Recordset As ADODB.Recordset
Dim A1 As Range
'Without Password
dbpath = "C:\Documents and Settings\n574824\Databases
Set conn = New ADODB.Connection
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open dbpath
End With
''''''''''''''''''''''''''
'////30 year WAVG
' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT [Expr1] " '<--- space added to
Src = Src & "FROM WA "
Src = Src & "WHERE ([LoanTerm] = '30' ) And [CompanyID] = " & TradeLimit.ComboBox1.Value
.Open source:=Src, ActiveConnection:=conn
'Write the recordset
Sheet9.Range("L10").Value = .Fields(0)
End With
''''''''''''''''''''''''''
'////20 year WAVG
' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT [Expr1] " '<--- space added to
Src = Src & "FROM WA "
Src = Src & "WHERE ([LoanTerm] = '20' ) And [CompanyID] = " & TradeLimit.ComboBox1.Value
.Open source:=Src, ActiveConnection:=conn
End With
Set Recordset = Nothing
conn.Close
Set conn = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Jim, Are you talking to me ?
Yes. Sorry, I should have prefixed with your name or (Off-Topic).
> I always thought it was if there were zero records, .BOF and .EOF would be true.
Yes, but .BOF And .EOF = True implies .BOF Or .EOF = True, which is a general condition.
Yes, but .BOF And .EOF = True implies .BOF Or .EOF = True, which is a general condition.
ASKER
Thank you both!
If there are more than one record, and you are starting to iterate through it, then .BOF would be true, but not .EOF