473,606 Members | 2,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I use a RecordSetClone in SQL

Hello

Can I write an SQL statement in code using a RecordSetClone of an open form?

something like:
MySQL = "UPDATE Me!Child0.Form. RecordSetClone SET
Me!Child0.Form. RecordSetClone. MyField = -1:"
DoCmd.RunSQL MySQL

Note: in the above example MyField is the Control Source of a Textbox in
Me!Child0 subform
(The above example gives me "Syntax error in Update statement" )

If it is possible to use a RecordSetClone in an SQL how would I write the
statement?

Thanks
G.Gerard
May 27 '06 #1
3 6193
No.

May 28 '06 #2
G Gerard wrote:
Hello

Can I write an SQL statement in code using a RecordSetClone of an open form?

something like:
MySQL = "UPDATE Me!Child0.Form. RecordSetClone SET
Me!Child0.Form. RecordSetClone. MyField = -1:"
DoCmd.RunSQL MySQL

Note: in the above example MyField is the Control Source of a Textbox in
Me!Child0 subform
(The above example gives me "Syntax error in Update statement" )

If it is possible to use a RecordSetClone in an SQL how would I write the
statement?

Thanks
G.Gerard


Here is some code I tried behind a form:

'-------Begin code behind form
Private Sub cmdRename_Click ()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strSQL As String

Set MyDB = CurrentDb
strSQL = "SELECT EFirstName FROM tblEmployees WHERE EID = 1;"
Set MyRS = MyDB.OpenRecord set(strSQL, dbOpenDynaset)

Call UpdateRecordset (MyDB, MyRS)
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
Me.Requery
MsgBox ("Done.")
End Sub

Private Sub UpdateRecordset (MyDB1 As DAO.Database, MyRS1 As
DAO.Recordset)
If MyRS1.Fields(0) = "Joe" Then
MyRS1.Edit
MyRS1(MyRS1.Fie lds(0).Name) = "Frank"
MyRS1.Update
End If
End Sub
'-------End code behind form

Note: I get to reuse a table from a different example.

tblEmployees
EID AutoNumber
EFirstName Text
ELastName Text

EID EFirstName ELastName
1 Joe Young
2 King Kong
3 The Hulk

After clicking on the command button the table becomes:

EID EFirstName ELastName
1 Frank Young
2 King Kong
3 The Hulk

The A97 help file states that the RecordsetClone is read-only so you
can't use it directly to update records.

I decided to make sure that bound values would not interfere with the
edit. I set the RecordSource of the form to tblEmployees and had a
textbox with a ControlSource bound to the EFirstName field. I changed
'Frank' back to 'Joe' in the table, then opened the form and clicked
the command button. The name in the textbox changed to 'Frank' just
before the 'Done.' message popped up.

James A. Fortune
CD********@Fort uneJames.com

If a police car, an ambulance, a fire truck and a mail truck all meet
at an intersection the mail truck has the right of way. -- James Allen

May 28 '06 #3
G Gerard wrote in message
<i6************ ********@ursa-nb00s0.nbnet.nb .ca> :
Hello

Can I write an SQL statement in code using a RecordSetClone of an
open form?

something like:
MySQL = "UPDATE Me!Child0.Form. RecordSetClone SET
Me!Child0.Form. RecordSetClone. MyField = -1:"
DoCmd.RunSQL MySQL

Note: in the above example MyField is the Control Source of a Textbox
in Me!Child0 subform
(The above example gives me "Syntax error in Update statement" )

If it is possible to use a RecordSetClone in an SQL how would I write
the statement?

Thanks
G.Gerard


I think it should be possible to do something like this

strSql = "UPDATE " & Me!Child0.Form. RecordSetClone. Name & _
" SET MyField = -1"
currentdb.execu te strSql, dbfailonerror
Me!Child0.Form. Requery

as long as the form recordset is DAO and the recordsource specifies a
table or query which is updateable (not an SQL string).

Or do you also wish to pick up the controlsource dynamicly?

strSql = "UPDATE " & Me!Child0.Form. RecordSetClone. Name & " Set " & _
Me!Child0.Form. Controls("MyFie ld").Controlsou rce & " = -1"

--
Roy-Vidar
May 28 '06 #4

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

Similar topics

13
2690
by: Seth Spearman | last post by:
Hey guys, I have the following code: '****************************************************** If Not Me.NewRecord Then Dim rs As DAO.Recordset Dim strBookmark As String Set rs = Forms("frmMaster").RecordsetClone 'set an instance of form master recordset clone
1
6311
by: Gerry Abbott | last post by:
Hi all, I have a function I use to sort the recordset behind a form on designated fields of the form (see code below). I pass the field name, and trigger this function with the click of the field heading. However I'm using filters at different times on the underlying form recordset, but want the functionality of being able to sort the resulting recordset using my function. I don't want to have to pass the filter to the fuinction if I...
3
13947
by: Anthony Kroes | last post by:
I have a subform on a form and they are not linked. On the main form is a text box where the user types in a number. When that number changes, I have some code to make the corresponding text field in the subform default its value so that the next record created uses the value from the box on the main form. So far so good - works fine. What I also need to do at the same time is change all *existing* records on the subform to that same...
3
2598
by: Ian Bailey | last post by:
I have developed a routine that opens a number of forms with each form being positioned on a particular record. I am using the Recordsetclone to find the record and then setting the form bookmark to the recordsetclone bookmark. The first form is already open and so is just positioned to the desired record. The second and subsequent forms have underlying queries that filter using a value from one of the controls on the first form.
3
2456
by: GGerard | last post by:
Hello I am trying to refer in code to the RecordsetClone of a subform datasheet but I'm getting syntax errors. This is what I am writing: Set MyDB = DBEngine.Workspaces(0).Databases(0) MySQL = "SELECT Sum(*) AS Expr1 FROM Forms!Form1!Child0.Form.RecordsetClone;"
22
5018
by: Br | last post by:
First issue: When using ADPs you no longer have the ability to issue a me.refresh to save the current record on a form (the me.refresh does a requery in an ADP). We usually do this before calling up another form or report that uses some of the same data. We came up with a work around that saves the current record's ID, does a
10
5768
by: d.francis | last post by:
I have converted an Access 97 database to Access 2003 The following code now fails and returns Run-time error '3420' Dim rst as DAO.recordset Set rst = Forms!frm1!frm2.Form.RecordsetClone I have installed the latest updates to Access and Jet I have checked the references and they are fine I have disabled the 'Sandbox' mode
2
1955
imrosie
by: imrosie | last post by:
Hello, I have a search form that uses a row query to locate a customer by customerID and first & last names, so it's an unbound control. I also have two events associated with this control, 'NotInList' (for customer not in table) and AfterUpdate event which (uses RecordsetClone by customeriD. The Recordsetclone event allows for the other data stored associated with the customer that's located. However, a strange thing occurs when a new...
0
8016
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
7955
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8431
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
8096
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,...
1
5966
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
5466
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
3937
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...
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1557
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.