Hello again Accessors.
I am struggling with recordsets. I believe I understand what they are but the examples I have researched are very inconsistant. They're written differently from each other and include and miss out different things from each other. The explanatory text is usually basic and leaves me feeling dumber each time I read them.
1. I shall be connecting to tables both inside and outside the original .mdb application, just to be awkward. Therefore I believe I need to use ADO for this. I have set it in my tools / references as higher in the list than dao.
2. Some online examples show the routine opening a connection before recordsets etc. are used. Do I do this even whan accessing table within the original .mdb? Do I do this once at the beginning of the program and leave it open or do it each time a subroutine that accesses the external table is called? I suppose I need to know the scope of an open connection.
3. On a button click, I wish to copy the content of a field in table 1 to a field in a new record, a log file, in table 2. (These are local not external tables.) Do I need to open a record set for each table then copy between them? Or open a recordset for the destination table and get the data from the originating table, how?
4. I am an absolute newbie trying to learn using online snippets from Google searches! (Hardly the way to get a qualification, but it's what I've got!) I don't want to waste my or your time, so can anyone tidy up / correct the below code please? I know it's pants, but I'm not sure why!
Can you explain a bit of detail about the correct way of doing this? Once I understand it better I hope I won't have to keep asking stupid questions.
Code:
'Initialise
' Allocate a block of memory for the db
Dim db As Database
' Allocate a block of memory for the recordset
Dim rsetUsers As Recordset
'Point db to the current database
Set db = CurrentDb
'Open the table "tblLoggedOnUser" for reading and writing.
rsetUsers.Open "tblLoggedOnUser", , adOpenDynamic, adLockOptimistic
'This is (I think) the DAO version?
'Set rsetUsers = db.OpenRecordset("tblLoggedInUser")
'Add new record to tblLoggedInUser
rsetUsers.AddNew
'Copy the info from tblDBUsers to make a log of the visit
'rsetUsers!ID = ??
'Clean up memory
rsetUsers.Update
rsetUsers.Close
Set rsetUsers = Nothing
Set db = Nothing
"Object variable or With block variable not set"
Any light that you can shine
will be gratefully recieved. Thank you.
Mike. (UK)