Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
Rhonda Fischer #1
=> Recordset value in ADO
Hello,
I have created a recordset in ADO and would like to perform
two different operations dependant on if the recordset
contains one or greater than one record. However I
seem only to receive the .Recordset value of -1,
disregardless of how many records are contained in the
cursor. How can I get around this?
The code I am using is as follows.
Thank you for any suggestions you might have.
Kind Regards
Rhonda
Sub displayStaffSurname(inSurname As String)
On Error GoTo Err_displayStaffSurname
'Proceedure called from
' => Form: FrmPersonnel
' => CmdBtn: cmdSearch_Click()
'Declaration
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
'Open the connection
Set cnn = CurrentProject.Connection
'Set up the Command objects's Connection, SQL and
parameter types
With cmd
.ActiveConnection = cnn
.CommandText = "SELECT * FROM tblStaff WHERE
Surname = " & "'" & inSurname & "'"
End With
Set rst = cmd.Execute
If rst.EOF Then
MsgBox "No Matching Surname, Try Agan :-)",
vbOKOnly, "Incorrect Entry"
ElseIf (rst.RecordCount = 1) Then '**** PROBLEM HERE
'display singular record on Main Personnel Form
Forms![frmPersonnel]!txtSurname = Trim(rst!Surname)
Forms![frmPersonnel]!txtFirstName = Trim(rst!
Firstname)
Forms![frmPersonnel]!txtDepot = Trim(rst!Depot)
Forms![frmPersonnel]!txtDepartment = Trim(rst!
Department)
ElseIf (rst.RecordCount > 1) Then '**** PROBLEM HERE
'loop through and populate fields on a different
'form
End If
cnn.Close
Set cmd = Nothing
Exit_displayStaffSurname:
Exit Sub
Err_displayStaffSurname:
MsgBox Err.Description
Resume Exit_displayStaffSurname
End Sub
Rhonda Fischer Guest
-
ASP Recordset Help!
Hi, I have been trying to construct a results page in dreamweaver/asp if i put a search in with one parameter it works fine (ie, select name from... -
Using a Recordset
I'm trying to expand my web design skills by learning how to include some dynamic content in a site. Currently I have an Access database, and... -
Is this possible with a recordset?
Hello, Looking for some expert help. I am using Dreamweaver MX 2004. I have a need that I was wondering if it was possible accomplish using a... -
ADO - Recordset
I was wondering if anyone can help me. I've converting an already existing system (designed in Access which produces reports for the accounts dept)... -
RecordSet.Move or RecordSet.AbsolutePosition??
Hi, I'm trying to use either one of these methods to position the cursor in a specific position inside a recordset, but neither one seems to... -
Daniel Johnson #2
Re: => Recordset value in ADO
Rhonda,
The RecordCount property returns -1 if the number of records is unknown at
runtime.
Open the RecordSet as a ForwardOnly or Static cursor instead.
rst.Open sSQL, cnn, adOpenStatic, adLockReadOnly
or
rst.Open sSQL, cnn, adOpenForwardOnly, adLockReadOnly
Also, I wouldn't bother using the Command object.
I hope this helps,
Danny.
"Rhonda Fischer" <Rhonda.Fischer@Turners-Distribution.com> wrote in message
news:073401c3479e$5b38cd80$a601280a@phx.gbl...> Hello,
>
> I have created a recordset in ADO and would like to perform
> two different operations dependant on if the recordset
> contains one or greater than one record. However I
> seem only to receive the .Recordset value of -1,
> disregardless of how many records are contained in the
> cursor. How can I get around this?
>
> The code I am using is as follows.
>
> Thank you for any suggestions you might have.
>
> Kind Regards
> Rhonda
>
>
> Sub displayStaffSurname(inSurname As String)
> On Error GoTo Err_displayStaffSurname
>
> 'Proceedure called from
> ' => Form: FrmPersonnel
> ' => CmdBtn: cmdSearch_Click()
>
> 'Declaration
> Dim cnn As ADODB.Connection
> Dim cmd As ADODB.Command
> Dim rst As ADODB.Recordset
>
> Set cnn = New ADODB.Connection
> Set cmd = New ADODB.Command
> Set rst = New ADODB.Recordset
>
> 'Open the connection
> Set cnn = CurrentProject.Connection
>
> 'Set up the Command objects's Connection, SQL and
> parameter types
> With cmd
> .ActiveConnection = cnn
> .CommandText = "SELECT * FROM tblStaff WHERE
> Surname = " & "'" & inSurname & "'"
> End With
>
> Set rst = cmd.Execute
>
> If rst.EOF Then
> MsgBox "No Matching Surname, Try Agan :-)",
> vbOKOnly, "Incorrect Entry"
> ElseIf (rst.RecordCount = 1) Then '**** PROBLEM HERE
> 'display singular record on Main Personnel Form
> Forms![frmPersonnel]!txtSurname = Trim(rst!Surname)
> Forms![frmPersonnel]!txtFirstName = Trim(rst!
> Firstname)
> Forms![frmPersonnel]!txtDepot = Trim(rst!Depot)
> Forms![frmPersonnel]!txtDepartment = Trim(rst!
> Department)
> ElseIf (rst.RecordCount > 1) Then '**** PROBLEM HERE
> 'loop through and populate fields on a different
> 'form
> End If
>
>
> cnn.Close
> Set cmd = Nothing
>
> Exit_displayStaffSurname:
> Exit Sub
>
> Err_displayStaffSurname:
> MsgBox Err.Description
> Resume Exit_displayStaffSurname
>
> End Sub
Daniel Johnson Guest
-
Bob Barrows #3
Re: => Recordset value in ADO
Daniel Johnson wrote:
ForwardOnly returns -1. Since only a single record is retrieved at a time,> Rhonda,
>
> The RecordCount property returns -1 if the number of records is
> unknown at runtime.
> Open the RecordSet as a ForwardOnly or Static cursor instead.
the provider will not know the number of records until the last record in
the resultset has been retrieved.
Bob Barrows
Bob Barrows Guest
-
Rhonda Fischer #4
Re: => Recordset value in ADO
Thank you very much it worked, I'm very happy :)
Bestest Regards
Rhonda
records is>-----Original Message-----
>Daniel Johnson wrote:>> Rhonda,
>>
>> The RecordCount property returns -1 if the number ofinstead.>> unknown at runtime.
>> Open the RecordSet as a ForwardOnly or Static cursorretrieved at a time,>ForwardOnly returns -1. Since only a single record isthe last record in>the provider will not know the number of records until>the resultset has been retrieved.
>
>Bob Barrows
>
>
>.
>Rhonda Fischer Guest



Reply With Quote

