Re: Passing a recordset to a form
From: Brendan Reynolds (brenreyn)
Date: 08/19/04
- Next message: Jason Gyetko: "DoCmd.PrintOut Works for MDB but not MDE"
- Previous message: Lynn Trapp: "Re: Automatically updating fields"
- In reply to: Matthew DeAngelis: "Passing a recordset to a form"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Aug 2004 15:35:49 +0100
It's not an area I'm familiar with myself, I'd usually set the form's
RecordSource property instead. Looking at the example in the help file,
though, I notice that a) the Recordset variable is declared as Public*
outside the procedure (otherwise it would go out of scope as soon as the
code exited the procedure) and b) the CursorLocation property of the
recordset is set to adUseClient. The example is also using adOpenKeyset
rather than adOpenDynamic, as well as specifying the lock type as
adLockOptimistic. My guess is that the CursorLocation may be the important
property here, but I can't say for sure - ADO help is not functioning on
this PC.
*Actually 'Global' in the example, but I can't imagine why - that's obsolete
syntax only maintained for backward compatibility.
Global rstSuppliers As ADODB.Recordset
Sub MakeRW()
DoCmd.OpenForm "Suppliers"
Set rstSuppliers = New ADODB.Recordset
rstSuppliers.CursorLocation = adUseClient
rstSuppliers.Open "Select * From Suppliers", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set Forms("Suppliers").Recordset = rstSuppliers
End Sub
-- Brendan Reynolds (MVP) http://brenreyn.blogspot.com The spammers and script-kiddies have succeeded in making it impossible for me to use a real e-mail address in public newsgroups. E-mail replies to this post will be deleted without being read. Any e-mail claiming to be from brenreyn at indigo dot ie that is not digitally signed by me with a GlobalSign digital certificate is a forgery and should be deleted without being read. Follow-up questions should in general be posted to the newsgroup, but if you have a good reason to send me e-mail, you'll find a useable e-mail address at the URL above. "Matthew DeAngelis" <mattd@proquestvc.com> wrote in message news:umiFLiGhEHA.904@TK2MSFTNGP09.phx.gbl... > Hello, > > I am coding a button that will filter a recordset and pass that > recordset to the form. I have tested the filter and it works fine but, > when I try to pass the recordset to the form, I get the following error: > "Runtime error '3251': Operation is not supported for this type of > object." The help file says this means that this action is normally > supported, but is not in this specific instance. Here is the code > snippet I am using: > > Dim rst As New ADODB.Recordset > Dim cnn As ADODB.Connection > Dim stDocName As String > stDocName = "frm: AllCompanies" > Set cnn = CurrentProject.Connection > rst.Open "[qry: frmPrincipalSearch]", cnn, adOpenDynamic > rst.Filter = "Principal Like *" & Forms!frmSearch!Principal & "*" > DoCmd.OpenForm stDocName > With Forms![frm: AllCompanies] > .Recordset = rst > End With > > The debugger highlights the .Recordset = rst line. Does anyone know > what I am doing wrong? Please note that I am very new to working with > recordsets! > > > Thanks, > Matt
- Next message: Jason Gyetko: "DoCmd.PrintOut Works for MDB but not MDE"
- Previous message: Lynn Trapp: "Re: Automatically updating fields"
- In reply to: Matthew DeAngelis: "Passing a recordset to a form"
- Messages sorted by: [ date ] [ thread ]