I am having a bit of a problem with Dlookup criteria and have looked through quite a few threads but none seem to answer my problem,
I am updating a month calendar changing the backcolor of the box if the criteria match.
This actually works fine.
The problem is that it needs to be specific to a field.
What is actually happening is! It goes through all the records and populates the calendar with all the data instead of just the record I am on.
Here is the code.
Sub RefDates()
Dim D1 As Variant, D2 As Integer, D3 As Integer, MaintTp
If IsNull(Me![AssetID]) Then
MsgBox ("There is no record for this asset number " _
& "Try another record."
Exit Sub
End If
Me![scrMonth] = Format(Me![scrCDate], "mmmm"
Me![scrYear] = Format(Me![scrCDate], "yyyy"
D1 = DateSerial(Year(Me![scrCDate]), Month(Me![scrCDate]), 1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbMonday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00"
) = Day(D1)
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00"
).ForeColor = 8421504
Else
Me("C" & Format(D3, "00"
).ForeColor = 0
'If Me(strt).ForeColor = -2147483634 Then
End If
'#######################################################
MaintTp = DLookup("AssetID", "Maintenance", " [MaintAssetID] = " & [AssetID] & " AND [MaintenanceDate] = #" & Format(D1, "mm/dd/yy"
& "#"
'#######################################################
If IsNull(MaintTp) Then
MaintTp = 0
End If
Select Case MaintTp
Case 0
Me("C" & Format(D3, "00"
).BackColor = 12632256
Case 1
Me("C" & Format(D3, "00"
).BackColor = 65280
Case 2
Me("C" & Format(D3, "00"
).BackColor = 255
Case Else
Me("C" & Format(D3, "00"
).BackColor = 3355443
Me("C" & Format(D3, "00"
).ForeColor = 16777215
End Select
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Loop
Me.Repaint
End Sub
if I change the criteria to
MaintTp = DLookup("AssetID", "Maintenance", "SELECT DISTINCT [MaintAssetID] = " & [AssetID] & " AND [MaintenanceDate] = #" & Format(D1, "mm/dd/yy"
& "#"
it gives me a syntax error.
Can anyone help please
Dandl![[noevil] [noevil] [noevil]](/data/assets/smilies/noevil.gif)
I am updating a month calendar changing the backcolor of the box if the criteria match.
This actually works fine.
The problem is that it needs to be specific to a field.
What is actually happening is! It goes through all the records and populates the calendar with all the data instead of just the record I am on.
Here is the code.
Sub RefDates()
Dim D1 As Variant, D2 As Integer, D3 As Integer, MaintTp
If IsNull(Me![AssetID]) Then
MsgBox ("There is no record for this asset number " _
& "Try another record."
Exit Sub
End If
Me![scrMonth] = Format(Me![scrCDate], "mmmm"
Me![scrYear] = Format(Me![scrCDate], "yyyy"
D1 = DateSerial(Year(Me![scrCDate]), Month(Me![scrCDate]), 1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbMonday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00"
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00"
Else
Me("C" & Format(D3, "00"
'If Me(strt).ForeColor = -2147483634 Then
End If
'#######################################################
MaintTp = DLookup("AssetID", "Maintenance", " [MaintAssetID] = " & [AssetID] & " AND [MaintenanceDate] = #" & Format(D1, "mm/dd/yy"
'#######################################################
If IsNull(MaintTp) Then
MaintTp = 0
End If
Select Case MaintTp
Case 0
Me("C" & Format(D3, "00"
Case 1
Me("C" & Format(D3, "00"
Case 2
Me("C" & Format(D3, "00"
Case Else
Me("C" & Format(D3, "00"
Me("C" & Format(D3, "00"
End Select
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Loop
Me.Repaint
End Sub
if I change the criteria to
MaintTp = DLookup("AssetID", "Maintenance", "SELECT DISTINCT [MaintAssetID] = " & [AssetID] & " AND [MaintenanceDate] = #" & Format(D1, "mm/dd/yy"
it gives me a syntax error.
Can anyone help please
Dandl
![[noevil] [noevil] [noevil]](/data/assets/smilies/noevil.gif)