Record data when a form opens

Dan25e

Registered User.
Local time
Today, 09:40
Joined
Dec 3, 2014
Messages
33
Hi Peeps,

I'm trying to add data about a form to a table when the On_Current event fires. The data I want to add is:
windows login username
date and time the On_Current event occurred
name of the form that was opened
that the form was opened
the number of the record (ID) in the table the form is based on

I have the following code

Private Sub Form_Current()
If Me.NewRecord Then
Call FlimOpen("OR IR No", "OPENED")
Else
Call FlimOpen("OR IR No", "OPENED")
End If
End Sub

which I'm trying to get to fire

Option Compare Database

Sub FlimOpen(ID As String)
On Error GoTo FlimOpen_Err
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim ctl As Control
Dim datTimeCheck As Date
Dim strUserID As String
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM tblIRAuditTrail", cnn, adOpenDynamic, adLockOptimistic
datTimeCheck = Now()
strUserID = Environ("USERNAME")
Select Case UserAction
Case "OPENED"
For Each ctl In Screen.ActiveForm.Controls
If ctl.Tag = "Audit" Then

With rst
.AddNew
![DateTime] = datTimeCheck
![UserName] = strUserID
![FormName] = Screen.ActiveForm.Name
![Action] = "Form Opened"
![RecordID] = Screen.ActiveForm.Controls(ID).Value
.Update
End With

End If
Next ctl
Case Else
With rst
.AddNew
![DateTime] = datTimeCheck
![UserName] = strUserID
![FormName] = Screen.ActiveForm.Name
![Action] = UserAction
![RecordID] = Screen.ActiveForm.Controls(ID).Value
.Update
End With
End Select
FlimOpen_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
FlimOpen_Err:
MsgBox Err.Description, vbCritical, "Database error. Please contact your database administrator"
Resume FlimOpen_Exit
End Sub

Excuse the use of 'FlimOpen' but I needed a unique word that I would remember (inspired by FlimFlam the cat on the children's channel CBeebies here in the UK)

I try to compile and I get an error about the wrong number of arguments or invalid property assignment. However, the event does fire correctly when I open the form or move from one record to another so something's workin!

As usual, any help would be greatly appreciated

Dan
 
You are passing in 2 arguments to your procedure which is expecting 1

FlimOpen("OR IR No", "OPENED")

Sub FlimOpen(ID As String)
 

Users who are viewing this thread

Back
Top Bottom