mactheknife
Registered User.
- Local time
- Today, 01:53
- Joined
- Jan 6, 2014
- Messages
- 12
I want to be able to show all records from tblRecords where, The [tblUser][PositionID] = The Value selected on the list box.The problem being I don't really know how to do this with them all being on seperate tables and linked via relationships. I.e. [tblRecords] only holds the UserID, [tblUser] has the PositionID.
I also need this value to keep building towards my filter string, i.e. I can select this position ID and records from within the past 4 days.I've attached pics of the form and relationships.Thankyou.
Here is my current code:
I also need this value to keep building towards my filter string, i.e. I can select this position ID and records from within the past 4 days.I've attached pics of the form and relationships.Thankyou.
Here is my current code:
Code:
Option Compare Database
Option Explicit
Private Sub cmdReset_Click()
'Purpose: Clear all the search boxes in the Form Header, and show all records again.
Dim ctl As Control
'Clear all the controls in the Form Header section.
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType
Case acTextBox, acListBox
ctl.Value = Null
Case acCheckBox
ctl.Value = False
End Select
Next
'Remove the form's filter.
Me.FilterOn = False
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = True
MsgBox "You cannot add new records to the search form.", vbInformation, "Permission denied."
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(False)"
Me.FilterOn = True
End Sub
Private Sub LstDays_AfterUpdate()
Dim startDate As Date
Dim endDate As Date
Dim period As String
period = Me.LstDays
startDate = DateSerial(Year(Date), Month(Date), Day(Date))
Select Case period
Case "Today"
endDate = DateAdd("d", 1, startDate)
Case "Yesterday"
endDate = startDate
startDate = DateAdd("d", -1, startDate)
Case "Last 4 Days"
endDate = startDate
startDate = DateAdd("d", -4, endDate)
Case "Last 9 Days"
endDate = startDate
startDate = DateAdd("d", -9, endDate)
End Select
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
'Number field example.
If Not IsNull(Me.LstUser) Then
strWhere = strWhere & "([User] = " & Me.LstUser & ") AND "
End If
'Date field example.
If Not IsNull(Me.LstDays) Then
strWhere = strWhere & "([EnteredOn] >= " & Format(startDate, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
Private Sub LstDays_BeforeUpdate(Cancel As Integer)
End Sub