N
NoodNutt
G'day Ppl
Grabbed this Compact Code from the following link but need some advice
please, am still a mushroom when it comes to DLookup & SQL.
http://www.tek-tips.com/faqs.cfm?fid=4998
Function MaintenanceCheck()
On Local Error GoTo MCError1
Dim stDatabaseName As String
Dim stLastCompacted As String
Dim stMessage As String
Dim stSQl As String
Dim stTimeNow As String
Dim stToday As String
stToday = Format$(Now, "yyyymmdd")
stLastCompacted = DLookup("[ParameterValue]", "tblControl1",
"[ParameterName] = 'LastCompacted'")
stDatabaseName = DLookup("[ParameterValue]", "tblControl1",
"[ParameterName] = 'DatabaseName'")
'My Code Interpretation
stLastCompacted = DLookup("[LastCompacted]", "tblCompactLog",
"[LastCompacted] = 'LastCompacted'")
stDatabaseName = DLookup("[DatabaseName]", "tblCompactLog",
"[DatabaseName] = 'DatabaseName'")
'My Table Structure Table Name = tblCompactLog
LastCompacted = Date/Time ("yyyymmdd")
DatabaseName = "MyDBNameV1" '
If stLastCompacted >= stToday Then
Exit Function
End If
stMessage = "You are the first person to use this database today." &
vbCrLf & vbCrLf
If intSecurityLevel = 1 Then
stMessage = stMessage & "Please ask someone with Data-entry or
Administrator permissions "
stMessage = stMessage & "to log in and run start of day maintenance."
MsgBox stMessage, vbInformation, stDatabaseName
Exit Function
Else
stMessage = stMessage & "When you click [OK], start of day maintenance
will take place." & vbCrLf & "Please wait ..."
MsgBox stMessage, vbInformation, stDatabaseName
stMessage = SysCmd(acSysCmdSetStatus, "Daily Maintenance In Progress ...
Please Wait")
End If
(Dunno what this is for, it doesn't work) stMessage =
WriteLogRecord("CompactDatabase", "MaintenanceCheck", "")
'My Code Interpretation
stSQl = "UPDATE tblCompactLog SET [tblCompactLog].[LastCompacted] = '" &
stToday & "' WHERE [tblCompactLog].[LastCompacted]= 'LastCompacted'"
This gives me an error message (Null Value)
stSQl = "UPDATE tblControl1 SET [tblControl1].[ParameterValue] = '" &
stToday & "' WHERE [tblControl1].[ParameterName] = 'LastCompacted'"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (stSQl)
DoCmd.SetWarnings (True)
CompactDatabase
Exit Function
MCError1:
MsgBox CStr(Err) & " - " & Error$
Resume MCEnd
MCEnd:
End Function
TIA
Mark.
Grabbed this Compact Code from the following link but need some advice
please, am still a mushroom when it comes to DLookup & SQL.
http://www.tek-tips.com/faqs.cfm?fid=4998
Function MaintenanceCheck()
On Local Error GoTo MCError1
Dim stDatabaseName As String
Dim stLastCompacted As String
Dim stMessage As String
Dim stSQl As String
Dim stTimeNow As String
Dim stToday As String
stToday = Format$(Now, "yyyymmdd")
stLastCompacted = DLookup("[ParameterValue]", "tblControl1",
"[ParameterName] = 'LastCompacted'")
stDatabaseName = DLookup("[ParameterValue]", "tblControl1",
"[ParameterName] = 'DatabaseName'")
'My Code Interpretation
stLastCompacted = DLookup("[LastCompacted]", "tblCompactLog",
"[LastCompacted] = 'LastCompacted'")
stDatabaseName = DLookup("[DatabaseName]", "tblCompactLog",
"[DatabaseName] = 'DatabaseName'")
'My Table Structure Table Name = tblCompactLog
LastCompacted = Date/Time ("yyyymmdd")
DatabaseName = "MyDBNameV1" '
If stLastCompacted >= stToday Then
Exit Function
End If
stMessage = "You are the first person to use this database today." &
vbCrLf & vbCrLf
If intSecurityLevel = 1 Then
stMessage = stMessage & "Please ask someone with Data-entry or
Administrator permissions "
stMessage = stMessage & "to log in and run start of day maintenance."
MsgBox stMessage, vbInformation, stDatabaseName
Exit Function
Else
stMessage = stMessage & "When you click [OK], start of day maintenance
will take place." & vbCrLf & "Please wait ..."
MsgBox stMessage, vbInformation, stDatabaseName
stMessage = SysCmd(acSysCmdSetStatus, "Daily Maintenance In Progress ...
Please Wait")
End If
(Dunno what this is for, it doesn't work) stMessage =
WriteLogRecord("CompactDatabase", "MaintenanceCheck", "")
'My Code Interpretation
stSQl = "UPDATE tblCompactLog SET [tblCompactLog].[LastCompacted] = '" &
stToday & "' WHERE [tblCompactLog].[LastCompacted]= 'LastCompacted'"
This gives me an error message (Null Value)
stSQl = "UPDATE tblControl1 SET [tblControl1].[ParameterValue] = '" &
stToday & "' WHERE [tblControl1].[ParameterName] = 'LastCompacted'"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (stSQl)
DoCmd.SetWarnings (True)
CompactDatabase
Exit Function
MCError1:
MsgBox CStr(Err) & " - " & Error$
Resume MCEnd
MCEnd:
End Function
TIA
Mark.