Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old May 16th, 2006, 03:25 AM
ApexData@gmail.com
Guest
 
Posts: 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

  #2  
Old May 16th, 2006, 03:45 AM
Bob Quintal
Guest
 
Posts: n/a

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.
  #3  
Old May 16th, 2006, 03:55 AM
Allen Browne
Guest
 
Posts: n/a

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]


  #4  
Old May 16th, 2006, 04:55 AM
ApexData@gmail.com
Guest
 
Posts: n/a

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



ThankYou

Took Your Advice and It Worked!

  #5  
Old May 16th, 2006, 05:55 AM
Lyle Fairfield
Guest
 
Posts: n/a

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.

  #6  
Old May 16th, 2006, 11:15 AM
rkc
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM