Anybody recommend a book to help

Chimp8471

Registered User.
Local time
Today, 08:46
Joined
Mar 18, 2003
Messages
353
i have over the past few months been tryiing to get my head around the code behind access.......

i have struggled to self teach myself what very little i know, however i was wondering if anybody could point me to some form of literature that can explain what the code is doing.

for example what this does and how ??

Function DataMake()
Dim db As Database
Dim rs As Recordset
Dim i As Integer

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblData")
For i = 30 To 1 Step -1
rs.AddNew
rs!dtmSample = Date - i
rs!strMaterialCode = "M2"
rs!intSurface = GetValue(80, 100, 100)
rs!intTestA1 = GetValue(8, 10, 10)
rs!intTestA2 = GetValue(0, 3, 5)
rs!intTestA3 = GetValue(1, 3, 5)
rs!intTestA4 = GetValue(6, 8, 10)


Cheers

Andy
 
Andy,

Hope this helps ...

Code:
Function DataMake() 
'
' Declare some variables to work with:
'
Dim db As Database   ' Represents your databases objects and properties
Dim rs As Recordset  ' To hold the contents of tblData
Dim i As Integer     ' To count 30 days (or records)
'
' Set a reference to the current database using the object db
'
Set db = CurrentDb() 
'
' Set a recordset (rs) to the collection of data in table tblData
'
Set rs = db.OpenRecordset("tblData") 
'
' Count backwards from 30 down to 1 (30, 29, 28 ... 1)
'
For i = 30 To 1 Step -1 
'
' Add a new record to tblData
'
rs.AddNew 
'
' Now, fill in the fields
'
' Each time through the Date will go from 30 days ago until yesterday
'
rs!dtmSample = Date - i 
'
' The MaterialCode is always "M2"
'
rs!strMaterialCode = "M2" 
'
' The following fields are going to be the same for all 30 records
' that are added.  They are provided by the GetValue function
' which is probably in a module in your database
'
rs!intSurface = GetValue(80, 100, 100) 
rs!intTestA1 = GetValue(8, 10, 10) 
rs!intTestA2 = GetValue(0, 3, 5) 
rs!intTestA3 = GetValue(1, 3, 5) 
rs!intTestA4 = GetValue(6, 8, 10) 
'
' At the end, there should be a rs!Update to save the work
'

Wayne
 
I saw that someone already posted while I was typing, but I figured I may as well post anyway since it may click with you.

You should be able to look up some of those keywords and methods in VBA Help to see what they're doing.
Code:
Function DataMake() 
Dim db As Database 
Dim rs As Recordset 
Dim i As Integer
Dim is declaring the variables that will be used in the function.
Code:
Set db = CurrentDb() 
Set rs = db.OpenRecordset("tblData")
This sets db to the database you currently have open. A recordset is a kind of result you get back from the database. In this case, the table, tblData. You assign this recordset to rs.
Code:
For i = 30 To 1 Step -1
This is a For...Next loop. At the end of the loop it will say "Next i". What this does is process all the code in between the beginning and the end of the loop with i = 30 and then apply "Step -1" to i, which makes it 29. It then repeats the loop with i = 29, and so on until it goes through the last time with i = 1.
Code:
rs.AddNew 
rs!dtmSample = Date - i 
rs!strMaterialCode = "M2" 
rs!intSurface = GetValue(80, 100, 100) 
rs!intTestA1 = GetValue(8, 10, 10) 
rs!intTestA2 = GetValue(0, 3, 5) 
rs!intTestA3 = GetValue(1, 3, 5) 
rs!intTestA4 = GetValue(6, 8, 10)
This is performing various functions based on the recordset (rs!dtmSample is referring to the dtmSample field in tblData). I'm not as familiar with AddNew and GetValue, but the VBA help file should explain them fairly well. Sorry I can't recommend any books =) I usually get everything I need from the help file or this forum.
 

Users who are viewing this thread

Back
Top Bottom