Here is some sample code I used in my Computer Based Training modules in
PowerPoint. I collect things like name, SSN, etc. in a UserForm on the
first slide, calculate a score of test questions, etc., then port them to
Access on the last slide. I have an Access database called
"TrainingData.mdb" with a table called "TrainingRecord" and the macro below
is called from a "Finished" button on the last slide.
Actually there is a whole lot more to the program, but this shell of the
Access code ought to get you started. The other thing to keep in mind that
the database MUST be in a folder on your network drive that folks have the
ability to write to. I usually have the client set up a specific folder for
all CBT files and set it to "Hidden" so it stays out of sight.
=============Code starts here================
'===============================
'This code is copyrighted and may not be used
'without permission from Professional Training Technologies, Inc.
'Please contact Bill Foley at (e-mail address removed)
'if you have any questions or comments.
'===============================
Sub SaveData()
' This is the database saving portion
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.RecordSet
Dim strDataSource As String
Dim strProvider As String
Dim strRecordSource As String
On Error GoTo Errorhandler
' Setup data source in database in same folder as presentation
strDataSource = "Data Source=" & Application.Presentations(1).Path &
"\TrainingData.mdb"
' This line used for Access 2000 and XP provider files
strProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
GoTo Complete
Errorhandler:
MsgBox "We were unable to access the database. Please call Bill Foley at
xxxx for assistance.", vbOKOnly, "Database Error"
GoTo Continue
Complete:
strRecordSource = "TrainingRecord"
'Open connection
cnn.Open strProvider & strDataSource
'Open recordset
rst.Open strRecordSource, cnn, adOpenDynamic, adLockOptimistic
'Keep in mind that these are my variables I use. Replace "strCBTNumber"
with your own,
'The key is to have the name of the Access field as the left hand
portion of each of these lines
'and the variables as the right hand portion of each line.
'add record and fill fields from data array
rst.AddNew
rst!SSN = strSSN
rst!firstname = strfirstname
rst!lastname = strlastname
rst!Feedback = strFeedback
rst!CBTNumber = strCBTNumber
rst!CBTtitle = strCBTTitle
rst!Score = Score
rst!DateTaken = Now
rst.Update
rst.Close
' Ensures the "Do you want to save changes" screen does not show up.
MsgBox "You have completed the PTT CBT Presentation. Please click the CLOSE
button to exit the CBT.", vbOKOnly, "Presentation completed"
Continue:
' Ensures the "Do you want to save changes" screen does not show up.
ActivePresentation.Saved = True
End Sub
=================End of code==============
Happy coding!
Bill Foley
www.pttinc.com