473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Open recordset question


Dear All,

I am trying to update data in a table using a button on a form.

the following bit of code does what I want:
Dim rst As Recordset, db As Database

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = 'Smith123'")

etc.
What I really want to do is to replace the 'Smith123' with either a
variable or preferably the contents of a field on the form.
I have tried all permutations of brackets and punctuation but can't get
it to work.

Any ideas please.
Thanks in advance

John Fox
--

Dr John E. Fox
Director

All prices quoted are in UK pounds and do not include any taxes.
************************************************** ****************
Alta Bioscience Email: al******@bham.ac.uk
The University of Birmingham Phone: +44 (0) 121 414 5450
Edgbaston, Birmingham Fax: +44 (0) 121 414 3376
B15 2TT, UK URL: www.altabioscience.bham.ac.uk

Nov 13 '05 #1
5 4206
Hm, should be:

Dim rst As Recordset, db As Database

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = '" & myVar &"'")

Nov 13 '05 #2

"John E. Fox" <al******@bham.ac.uk> schreef in bericht news:d7**********@redhat2.bham.ac.uk...

Dear All,

I am trying to update data in a table using a button on a form.

the following bit of code does what I want:


Dim rst As Recordset, db As Database

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = 'Smith123'")

etc.


What I really want to do is to replace the 'Smith123' with either a
variable or preferably the contents of a field on the form.
I have tried all permutations of brackets and punctuation but can't get
it to work.


Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = '" & textvar & "'") ' text var needs quotes (look carefully !!)
OR
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = " & numvar ) ' numeric var does not need quotes

Replace textvar or numvar with Forms!YourFom!YourConntrol if needed

Arno R
Nov 13 '05 #3
Thank you, it worked!
I'm sure I had tried that in one of my many attempts but must have had
something else wrong at the time.

John
Ace Calhoon wrote:
Hm, should be:

Dim rst As Recordset, db As Database

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = '" & myVar &"'")


--

Dr John E. Fox
Director

All prices quoted are in UK pounds and do not include any taxes.
************************************************** ****************
Alta Bioscience Email: al******@bham.ac.uk
The University of Birmingham Phone: +44 (0) 121 414 5450
Edgbaston, Birmingham Fax: +44 (0) 121 414 3376
B15 2TT, UK URL: www.altabioscience.bham.ac.uk

Nov 13 '05 #4
Thank you, it worked!
I'm sure I had tried that in one of my many attempts but must have had
something else wrong at the time.

John
Arno R wrote:
"John E. Fox" <al******@bham.ac.uk> schreef in bericht news:d7**********@redhat2.bham.ac.uk...
Dear All,

I am trying to update data in a table using a button on a form.

the following bit of code does what I want:
Dim rst As Recordset, db As Database

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = 'Smith123'")

etc.
What I really want to do is to replace the 'Smith123' with either a
variable or preferably the contents of a field on the form.
I have tried all permutations of brackets and punctuation but can't get
it to work.

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = '" & textvar & "'") ' text var needs quotes (look carefully !!)
OR
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = " & numvar ) ' numeric var does not need quotes

Replace textvar or numvar with Forms!YourFom!YourConntrol if needed

Arno R


--

Dr John E. Fox
Director

All prices quoted are in UK pounds and do not include any taxes.
************************************************** ****************
Alta Bioscience Email: al******@bham.ac.uk
The University of Birmingham Phone: +44 (0) 121 414 5450
Edgbaston, Birmingham Fax: +44 (0) 121 414 3376
B15 2TT, UK URL: www.altabioscience.bham.ac.uk

Nov 13 '05 #5
Thanks folks,
John


John E. Fox wrote:

Dear All,

I am trying to update data in a table using a button on a form.

the following bit of code does what I want:
Dim rst As Recordset, db As Database

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tablename _
WHERE [fieldname] = 'Smith123'")

etc.
What I really want to do is to replace the 'Smith123' with either a
variable or preferably the contents of a field on the form.
I have tried all permutations of brackets and punctuation but can't get
it to work.

Any ideas please.
Thanks in advance

John Fox


--

Dr John E. Fox
Director

All prices quoted are in UK pounds and do not include any taxes.
************************************************** ****************
Alta Bioscience Email: al******@bham.ac.uk
The University of Birmingham Phone: +44 (0) 121 414 5450
Edgbaston, Birmingham Fax: +44 (0) 121 414 3376
B15 2TT, UK URL: www.altabioscience.bham.ac.uk

Nov 13 '05 #6

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

Similar topics

6
by: wk6pack | last post by:
Hi, I have a question about my coding practise. I have a class method to return a value from a database. I open the connection do my search and dispose the reader. Open the reader with a new...
1
by: sumGirl | last post by:
Okay, I know nothing and I admit it. I have a simple form with a set of buttons at the top and depending on the button you push, displays some data at the button of the form. This is probably to...
6
by: John | last post by:
Just a general question... I'm currently using a combobox that when updated, opens a form with its recordset based on a query using the combo box value as the criteria. I'm I correct in...
4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
2
by: Colleyville Alan | last post by:
I ran into problems in an app in which I received a msg of "cannot lock the table, it is in use by another user". It turns out that I had opened a recordset with a command like set rstmyrecs =...
1
by: petersk | last post by:
Firstly I am an older person trying to teach myself to create a project and teach myself Access VBA programming along the way. I anticipate a number of problems I will need help with but here...
6
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2|...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
23
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
2
by: Kosmos | last post by:
I am opening the following connections as such although I am only referring to the first connection for this question: Dim con1 As ADODB.Connection Dim con2 As ADODB.Connection Dim recSet1 As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.