473,666 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set Form Recordset as ADO Recordset

I have a form with a search button. I'm using command parameters to
pass search criteria to a stored procedure. Here is my code:

Stored procedure:
CREATE PROCEDURE [dbo].[sp_GetPersConfi dential]
@strCriteria varchar(200)
AS
execute (@strCriteria)
GO

VB Code for Personnel form in Access:
Private Sub Form_Activate()

' if these booleans get lost, rebuild them
If blnGlobalsSet = False Then
Call GetSQLConn
Call CheckValidUser
End If

Set Rst = New ADODB.Recordset
Set Cmd = New ADODB.Command
Set Prm = New ADODB.Parameter
Cmd.ActiveConne ction = Cnn
Rst.ActiveConne ction = Cnn

If SrchCriteria = "" Then
SrchCriteria = "Select * from Personnel ORDER by Name"
End If

With Cmd
.ActiveConnecti on = Cnn
.CommandType = adCmdStoredProc
If Security = "C" Or Security = "A" Then
Cmd.CommandText = "sp_GetPersConf idential"
Else
Cmd.CommandText = "sp_GetPersNoCo nfidential"
End If
.Parameters.App end .CreateParamete r("@strCriteria ",
adVarChar, adParamInput, 200, SrchCriteria)

With Rst
.ActiveConnecti on = Cnn
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
End With
Set Rst = .Execute

MsgBox "SrchCriter ia = " & SrchCriteria & Chr(13) &
Rst.Fields(0).V alue
' Form.Recordset = Rst
' If Rst.RecordCount < 0 Then
' MsgBox "No Records match the criteria you have
entered.", 48, "Warning"
' End If
End With

' Set the form's Recordset property to the ADO recordset
Set Me.Recordset = Rst

' Rst.Close
Set Cmd = Nothing
Set Rst = Nothing
Set Prm = Nothing
MyCriteria = ""

End Sub

If I change the select statement to pass me the count of records, I
see the appropriate recordcount based on the search criteria I pass.
However, when I change it back to the asterisk and try to SET
ME.RECORDSET = RST, I get the error runtime error 7965 the object you
entered is not a valid recordset property. I tried moving the SET
ME.RECORDSET = RST to within the WITH RST construct, but get the same
error message.

When the form loads, all the fields show ?Name. If I add a msgbox to
show me the value of RST.FIELDS(0).V ALUE, I see valid data there. How
do I get this data to populate on my form? I see all these posts
about how this is supposed to work but I can't get the recordset or
recordsource properties to equal the ADO recordset data.

The Personnel form is not closed when the search button is clicked,
but it is requeried once the search form is closed.

Thanks for your help.
Nov 12 '05 #1
2 7923
I'm not sure if it has something to do with how the textboxes were
created. The conrol source entries are the field name entries from
the select statement. They don't include any reference to the ADO
recordset. Should they?
Nov 12 '05 #2
Has anyone done this successfully?
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11692
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. tCetecM1CUST (SQL Table that contains the Customer Information) tAccountingDetail (SQL Table that contains the information in the form) frmAccountingEntry (Access form used to enter data) spGetCustomerInformation (Stored Procedure which returns data using...
1
2188
by: ano1optimist | last post by:
Has anyone had success with using a command collection with parameters to run a stored procedure from sql server? I'm frustrated and have been spending way too much time trying to make this work. If you have a code sample, I'd love it. I've posted the code in a previous post but didn't have any responses as to what was occurring so I'm going to try once more. I have a connection to SQL 7 and use a command collection with one...
2
9670
by: Lyn | last post by:
If I have a form where the RecordSource property is set to the name of a table, then on opening the SingleForm form I can cycle through all the records in the table one at a time via Next and Previous buttons on the form. However, I only want to cycle through a subset of the table. I have a parent form which inputs selection criteria. With the selection criteria I create a RecordSet (using ADO) in the parent form. The RecordSet object...
2
2321
by: Lyn | last post by:
Hi, I am opening a form in Continuous mode to list the records from a recordset created in the calling form. The recordset object is declared as Public and is set into the new form's Recordset property during the Open event. According to the VBA Help file, setting the Recordset property may adjust the RecordSource property accordingly. If I set the RecordSource to blank in Design mode, it remains blank when the form is opened even...
1
3675
by: ZRexRider | last post by:
Hello, I have an MS-Access 2003 (ADP) project that uses SQL2000. I have a form that displays all "OPEN" items associated with a particular user. While viewing this form the user can click a search button that will let them review "CLOSED" or "SUBMITTED" items using the same form. I call a stored procedure to get the results of their "Search" and try
7
8363
by: marmottedodue | last post by:
Hello, I'm trying to debug an access project in which two kind of recordset are used: ADODB.recordset and DAO.recordset. I'm trying to set the whole project on DAO.recordset, but the following function does not work: Public Function GetRecordset(pstrCmdTxt As String, Optional pintCursorType As CursorTypeEnum = adOpenStatic) As Recordset ' was ADODB.recordset
2
18629
by: mfaisalwarraich | last post by:
Hello Everybody, Please tell me is there any way to populate an unbound form of MS Access 2002 with Recordset of an MS Access 2002 external database?? if yes then how??? I dont wana link tables/queries what i want is to hold all data in recordset and then display it into the form like continuous forms. thank u.
1
2603
by: charles.kendricks | last post by:
I have a form that is used to display patient records. It's default Recordset is set to a query which shows only current clients. I want to use an option box on the form to force the form to use the client table (tblClients) as it's source Recordset, which would display ALL clients (past and present), not just current clients. How do I accomplish this?
10
6114
by: sakurako97 | last post by:
hi, i am trying to find out if it is possible to pass the current recordset of a form to DoCmd.TransferText so i can export it as a .csv I know I can use querydefs etc, but it would be a much nicer solution if i could just loop through my subform1 and get the nested subform2 recordsets and pass them to the routine. has anyone had experience with this ? any ideas would be overwhelmingly appreciated!!
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.