By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Can't Make a Simple Change to a Record in a Single Table

P: n/a
Hello

I'm trying to save data to an Existing Record in a single table. These
fields
are not on my Form.
It is not saving the data to the record ???
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
strSQL = "SELECT * FROM [T-ADXOR] Where ID = 19"
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly)
If rs.BOF = False And rs.EOF = False Then
[Field1] = strPassStamp
[Field2] = strPermStamp
MsgBox [Field1] '<------- The values are showing but not saving
MsgBox [Field2] '<------- " "
End If

ALSO I am in desperate need of good reference material advice. I spend
ALL day
hunting for syntax & rules information. Anything one can recommend?

ThankYou

May 16 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Ap******@gmail.com" <Ap******@gmail.com> wrote in
news:11*********************@g10g2000cwb.googlegro ups.com:
Hello

I'm trying to save data to an Existing Record in a single
table. These fields
are not on my Form.
It is not saving the data to the record ???
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
strSQL = "SELECT * FROM [T-ADXOR] Where ID = 19"
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly)
If rs.BOF = False And rs.EOF = False Then
[Field1] = strPassStamp
[Field2] = strPermStamp
MsgBox [Field1] '<------- The values are showing but
not saving MsgBox [Field2] '<------- " "
End If

ALSO I am in desperate need of good reference material advice.
I spend ALL day
hunting for syntax & rules information. Anything one can
recommend?

ThankYou

add the two statements. I'd also qualify the two statements
explicitly
If rs.BOF = False And rs.EOF = False Then rs.edit '<---- added rs![Field1] = strPassStamp '<---- improved
rs![Field2] = strPermStamp '<---- improved rs.update '<---- added End If

as to documentation, buy or borrow Access Developer's Handbook
by Getz et al.

--
Bob Quintal

PA is y I've altered my email address.
May 16 '06 #2

P: n/a
Suggestions:

1. Make sure you have:
Option Explicit
at the top of every module. This will prevent Access from just making up a
variable for any name it does not recognise.

2. Before you can change the fields of a record, you need to Edit, and
afterwards to Update:
rs.Edit
'change the fields here
rs.Update

3. Refer to the fields of the recordset like this:
rs![Field1] = strPassStamp

Instead of opening a recordset, you could also do it by executing an Update
query statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<Ap******@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
Hello

I'm trying to save data to an Existing Record in a single table. These
fields
are not on my Form.
It is not saving the data to the record ???
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
strSQL = "SELECT * FROM [T-ADXOR] Where ID = 19"
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly)
If rs.BOF = False And rs.EOF = False Then
[Field1] = strPassStamp
[Field2] = strPermStamp
MsgBox [Field1] '<------- The values are showing but not saving
MsgBox [Field2] '<------- " "
End If

ALSO I am in desperate need of good reference material advice. I spend
ALL day
hunting for syntax & rules information. Anything one can recommend?

ThankYou

May 16 '06 #3

P: n/a

ThankYou

Took Your Advice and It Worked!

May 16 '06 #4

P: n/a
CurrentDb.Execute "UPDATE [T-ADXOR] SET [Field1] = '" & strPassStamp &
"', [Field2] = '" & strPermStamp & "' WHERE ID = 19"

(which will result in this query string being executed)
UPDATE [T-ADXOR] SET [Field1] = 'qwerty', [Field2] = 'asdfgh' WHERE ID
= 19
assuming
strPassStamp = "qwerty"
strPermStamp = "asdfgh"

I discourage the use of DAO Recordsets except in unusual circimstances.
They are slow, inefficient, dangerous and require (too) many lines of
code.

May 16 '06 #5

P: n/a
rkc
Ap******@gmail.com wrote:
ALSO I am in desperate need of good reference material advice. I spend
ALL day
hunting for syntax & rules information. Anything one can recommend?


The Help files via the Object Browser or any web search engine.
May 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.