Function fSetDefault(strDfault As String, strCurVal As String)
'From: http://support.microsoft.com/default.aspx?scid=kb;EN-US;202117
'This function sets the default value (a string) in the table "tblDefault" it requires three
'pieces of information to operate, the current windows username which it finds With the code below.
'the name of the default which is passed through the variable "strDfault" and the current
'value of that default,which is passed through the variable "strCurVal" the value of
'the default is saved in the table "tblDfault"
'Occasionally the table does not have a default entry listed. this code does not react,
'it does nothing, it does not throw an error or anything!
'Hence the need for the function "fInitaliseDfault" below.
'This function initializes the table, adding an entry if none exists, and throwing an error
'if creating a duplicate is attempted. This error is trapped and passed back to
'the function "fInitaliseDfault" as a boolean.
On Error GoTo Err_ErrorHandler
If fInitaliseDfault(strDfault, strCurVal) Then Exit Function 'Exit if creating a duplicate is attempted
Dim strUserName As String
'
'strUserName = fGetWinUserName() 'Your windows login name
strUserName = fUserGet
strUserName = "'" & strUserName & "'"
Dim strDfaultText As String
strDfaultText = "'" & strDfault & "'"
Dim strCurText As String
strCurText = "'" & strCurVal & "'"
Dim adoCon As ADODB.Connection
Dim adoCmd As ADODB.Command
Set adoCon = CurrentProject.Connection
Set adoCmd = New ADODB.Command
Dim strSQL As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
strSQL1 = "UPDATE tblDefaults SET tblDefaults.DfaultVal = "
strSQL2 = "WHERE (((tblDefaults.DfaultUser)="
strSQL3 = ") AND ((tblDefaults.DfaultFor)="
strSQL4 = "));"
strSQL = strSQL1 & strCurText & strSQL2 & strUserName & strSQL3 & strDfaultText & strSQL4
With adoCmd
.ActiveConnection = adoCon
.CommandType = adCmdText
.CommandText = strSQL
.Execute
End With
Exit_ErrorHandler:
adoCon.Close
Set adoCon = Nothing
Set adoCmd = Nothing
Exit Function 'Sub Property
Err_ErrorHandler:
Select Case Err.Number
Case 1 'Not sure if there is an error code (1) I have never seen it yet
MsgBox "produced by error code (1) please check your code ! Error Number >>> " _
& Err.Number & " Error Desc >> " & Err.Description, , conAppName
Case Else
MsgBox "Error From --- fGetDefault --- Error Number >>> " & Err.Number _
& " <<< Error Description >> " & Err.Description, , conAppName
End Select
Resume Exit_ErrorHandler
End Function 'fSetDefault()