A dumb question but .....

A

ashnook_news

In am running Access 2000 and want to write some Visual Basic code to read
and write from a table which is not open (active in anty form).

I have used the commands:

Dim tab_name As String
tab_name = "Activities"
DoCmd.OpenTable tab_name, , acAdd

to open and add a new record to table Activities, now how do I now read and
write to that new open record? Everything I try fails.

For example it has a field called Code1, how do I write to it?

I have tried
Activities!code1 = "fred"

to no avail!


(I am VERY new to Visual Basic and the Access book I have does not seem to
answer my question.)

Thanks
 
A

Albert D. Kallal

In code, we can process the data anyway we want.

However, the concept does not involve opening a table, but using what is
called a recordset

The following code will open a record set:

Dim rs As DAO.Recordset

set rs = currentdb.OpenRecordSet("select * from contacts")

Do While rs.EOF = False
Debug.Print rs!FirstName
rs.MoveNext
Loop
rs.Close
Set rs = Nothing

The above would print each FirstName from table contacts to the debug
window. The above is a good example of how to "process" a set of data.

In your case, you could feed the recordset the actual table name and go:

Dim rs As DAO.RecordSet

set rs = currentdb.OpenRecordSet("Activities")
rs.AddNew
rs!Code1 = "Fred"
rs.Update
rs.Close
Set rs = Nothing

You likely should get a book on ms-access, as some reading and learning will
really help you get up to speed.

Here is a on-line one:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bapp2000/html/acbatitle.asp

Here is a on-line book for access97
(this has very good into to writing code...and it will apply to a2000 also)
http://www.microsoft.com/accessdev/articles/bapp97/toc.htm

Also, for the above examples to work, you need to set the DAO 3.6 Library in
the tools->references. Here is the steps to do this:

http://www.attcanada.net/~kallal.msn/wordmerge/Details.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top