Connecting Tech Pros Worldwide Help | Site Map

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

ApexData@gmail.com
Guest
 
Posts: n/a
#1: May 16 '06
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

Bob Quintal
Guest
 
Posts: n/a
#2: May 16 '06

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


"ApexData@gmail.com" <ApexData@gmail.com> wrote in
news:1147745785.705916.90720@g10g2000cwb.googlegro ups.com:
[color=blue]
> 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
>[/color]

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


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.
Allen Browne
Guest
 
Posts: n/a
#3: May 16 '06

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


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.

<ApexData@gmail.com> wrote in message
news:1147745785.705916.90720@g10g2000cwb.googlegro ups.com...[color=blue]
> 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[/color]


ApexData@gmail.com
Guest
 
Posts: n/a
#4: May 16 '06

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



ThankYou

Took Your Advice and It Worked!

Lyle Fairfield
Guest
 
Posts: n/a
#5: May 16 '06

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


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.

rkc
Guest
 
Posts: n/a
#6: May 16 '06

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


ApexData@gmail.com wrote:
[color=blue]
> ALSO I am in desperate need of good reference material advice. I spend
> ALL day
> hunting for syntax & rules information. Anything one can recommend?[/color]

The Help files via the Object Browser or any web search engine.
Closed Thread