A query which will requery each time a form is opened or say a value is changed in a search filter.
When the user browsing the existing clients it looks like this, Img1. From can the user click on a client and then on the "Visa Klient" (Show Client) button, or double click on the clientID.
Then a windows with more detail information will open. Img2. The record is populated with the associated data exist for the sub form to the right. Except for the sub form which is listing all the "events" the client is associated with. As you can see both the records have a filed with the ClientID: "444444-4444". I'm trying to make the query only display the records with the same ClientID.
Then if the user would like to see more detailed information about a certain event he or she would be able to click choose an event then press on the "Visa" (Preview) button, or double click on the ClientID.
I'm not sure which form event this would be or how the could would look like.
Then i have also built my main menu with a navigation control.
The code.
I haven't written any code for the event form so far.
Main Menu. "Förhandsgranska/ Klient" (Preview/ Klient)
Code:
Option Compare DatabaseOption Explicit
Dim SrchVal As String
Dim SrchCrit As String
Dim LastFld As String
Dim fldName As String
Dim FlitStr As String
Private Function addCrLf(addValue As Integer) As String
'Convenience routine to build a concatenated string of carriage returns / line feeds
'given a specified count
Dim intCount As Integer
Dim strReturn As String
strReturn = ""
For intCount = 1 To addValue
strReturn = strReturn & vbCrLf
Next intCount
addCrLf = strReturn
End Function
Private Sub cboFliterCity_GotFocus()
Me.AllowEdits = True
If Nz(FlitStr, "") = "" Then
Me.cboFliterCity.RowSource = "SELECT DISTINCT tblClients.LastName FROM tblClients;"
Else
Me.cboFliterCity.RowSource = "SELECT DISTINCT tblClients.LastName FROM tblClients WHERE " & FlitStr & ";"
End If
Me.cboFliterCity.Dropdown
End Sub
Private Sub cboFliterCity_LostFocus()
Me.AllowEdits = False
End Sub
Private Sub cboFliterOro_GotFocus()
Me.AllowEdits = True
If Nz(FlitStr, "") = "" Then
Me.cboFliterOro.RowSource "SELECT DISTINCT tblErrand.Oro FROM tblErrand;"
Else
Me.cboFliterOro.RowSource "SELECT DISTINCT tblErrand.Oro FROM tblErrand WHERE " & FlitStr & ";"
End If
Me.cboFliterOro.Dropdown
End Sub
Private Sub cboFliterOro_LostFocus()
Me.AllowEdits = False
End Sub
Private Sub cboFlitLastName_GotFocus()
Me.AllowEdits = True
If Nz(FlitStr, "") = "" Then
Me.cboFlitLastName.RowSource = "SELECT DISTINCT tblClients.LastName FROM tblClients;"
Else
Me.cboFlitLastName.RowSource = "SELECT DISTINCT tblClients.LastName FROM tblClients WHERE " & FlitStr & ";"
End If
Me.cboFlitLastName.Dropdown
End Sub
Private Sub cboFlitLastName_LostFocus()
Me.AllowEdits = False
End Sub
Private Sub txtClientID_DblClick(Cancel As Integer)
Dim intID As String
intID = Me!intID
DoCmd.Close acForm, "frmClientsList"
DoCmd.Close acForm, "frmClientsMenu"
DoCmd.OpenForm "frmClientDetails", acNormal, "", "", acReadOnly, acDialog, OpenArgs:=intID
End Sub
Private Sub cmdVisa_Click()
Dim intID As String
intID = Me!intID
DoCmd.Close acForm, "frmClientsList"
DoCmd.Close acForm, "frmClientsMenu"
DoCmd.OpenForm "frmClientDetails", acNormal, "", "", acReadOnly, acDialog, OpenArgs:=intID
End Sub
Private Sub lblAnmäldDatum_Click()
If Me.OrderBy = "AnmäldDatum" Then
Me.OrderBy = "AnmäldDatum DESC"
Else
Me.OrderBy = "AnmäldDatum"
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Process
Dim ctl As control
Dim rs As Recordset
Select Case KeyCode
Case vbKeyEnd
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToLast
Case vbKeyHome
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToFirst
Case vbKeyUp
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToPrevious
Case vbKeyDown
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToNext
Case vbKeyRight, vbKeyLeft
Case vbKeyPageUp, vbKeyPageDown
KeyCode = 0
Case 9, 13 'tab or enter keys
Case 8 'backspace key
Case 48 To 57, 65 To 90
Set ctl = Screen.ActiveControl
fldName = ctl.Name
Select Case UCase(fldName)
Case "cboFlitLastName", "cboFliterCity", "cboFliterOro"
Exit Sub
End Select
If fldName <> LastFld Then
SrchVal = ""
End If
LastFld = fldName
SrchVal = SrchVal & Chr(KeyCode)
KeyCode = 0
If fldName = "Address" Then
SrchCrit = "[" & fldName & "] Like '*" & SrchVal & "*'"
Else
SrchCrit = "[" & fldName & "] Like '" & SrchVal & "*'"
End If
Set rs = Me.RecordsetClone
rs.FindFirst SrchCrit
If rs.NoMatch Then
MsgBox (" Record not found! ")
Else
Me.Bookmark = rs.Bookmark
End If
rs.Close
Case 107, 187
If SrchVal = "" Then
KeyCode = 0
Exit Sub
End If
Set ctl = Screen.ActiveControl
fldName = ctl.Name
KeyCode = 0
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark
rs.FindNext SrchCrit
If rs.NoMatch Then
MsgBox (" Record not found! ")
Else
Me.Bookmark = rs.Bookmark
End If
rs.Close
Case 109, 189
If SrchVal = "" Then
KeyCode = 0
Exit Sub
End If
Set ctl = Screen.ActiveControl
fldName = ctl.Name
KeyCode = 0
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark
rs.FindPrevious SrchCrit
If rs.NoMatch Then
MsgBox (" Record not found! ")
Else
Me.Bookmark = rs.Bookmark
End If
rs.Close
Case 27
KeyCode = 0
SrchVal = ""
Case Else
KeyCode = 0
End Select
Exit_Process:
Exit Sub
Err_Process:
Select Case Err.Number
Case 2046
Case 2474
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
Resume Exit_Process
End Sub
Private Sub Form_Open(Cancel As Integer)
'Me.OrderBy = "ID"
Me.OrderByOn = True
Me.AllowAdditions = False
Me.AllowEdits = False
Me.AllowDeletions = False
End Sub
Private Sub cmdDeleteClient_Click()
Dim strClient As String
If MsgBox(" Du är på väg att RADERA en KLIENT. ALLA relaterade objekt kommer att försvinna. Är du SÄKER på att du vill radera denna klienten? OBS! detta går inte att ångra! ", vbYesNo) = vbYes Then
strClient = "Klient: " & Me!intID & " # " & Me!txtClientID & addCrLf(2) & "Namn: " & addCrLf(1) & Me!FirstName & " - " & Me!LastName & addCrLf(2)
Me.AllowDeletions = True
DoCmd.RunCommand acCmdDeleteRecord
Me.AllowDeletions = False
MsgBox (" " & strClient & " Har raderats! ")
End If
End Sub
Private Sub lblClient_ID_Click()
If Me.OrderBy = "ClientID" Then
Me.OrderBy = "ClientID DESC"
Else
Me.OrderBy = "ClientID"
End If
Me.AllowAdditions = False
Me.AllowEdits = False
Me.AllowDeletions = False
End Sub
Private Sub lblePost_Click()
If Me.OrderBy = "ePost" Then
Me.OrderBy = "ePost DESC"
Else
Me.OrderBy = "ePost"
End If
End Sub
Private Sub lblFirstName_Click()
If Me.OrderBy = "FirstName" Then
Me.OrderBy = "FirstName DESC"
Else
Me.OrderBy = "FirstName"
End If
End Sub
Private Sub lblHomeNumnber_Click()
If Me.OrderBy = "HomeNumnber" Then
Me.OrderBy = "HomeNumnber DESC"
Else
Me.OrderBy = "LastName"
End If
End Sub
Private Sub lblID_Click()
If Me.OrderBy = "intID" Then
Me.OrderBy = "intID DESC"
Else
Me.OrderBy = "intID"
End If
End Sub
Private Sub lblLastName_Click()
If Me.OrderBy = "LastName" Then
Me.OrderBy = "LastName DESC"
Else
Me.OrderBy = "LastName"
End If
End Sub
Private Sub lblPhoneNumber_Click()
If Me.OrderBy = "PhoneNumber" Then
Me.OrderBy = "PhoneNumber DESC"
Else
Me.OrderBy = "PhoneNumber"
End If
End Sub
Private Sub lblPoastAdress_Click()
If Me.OrderBy = "PoastAdress" Then
Me.OrderBy = "PoastAdress DESC"
Else
Me.OrderBy = "LastPoastAdressName"
End If
End Sub
Private Sub lblPostOrt_Click()
If Me.OrderBy = "PostOrt" Then
Me.OrderBy = "PostOrt DESC"
Else
Me.OrderBy = "PostOrt"
End If
End Sub
Private Sub lblRegistreradDatum_Click()
If Me.OrderBy = "RegistreradDatum" Then
Me.OrderBy = "RegistreradDatum DESC"
Else
Me.OrderBy = "RegistreradDatum"
End If
End Sub
Private Sub lblRegistreradesAv_Click()
If Me.OrderBy = "RegistreradesAv" Then
Me.OrderBy = "RegistreradesAv DESC"
Else
Me.OrderBy = "RegistreradesAv"
End If
End Sub
Private Sub lblAvRegistreradDatum_Click()
If Me.OrderBy = "AvRegistreradDatum" Then
Me.OrderBy = "AvRegistreradDatum DESC"
Else
Me.OrderBy = "AvRegistreradDatum"
End If
End Sub
Sub BuildFlitStr()
FiltStr = ""
If Me!NameFlit <> "" Then
FlitStr = "[LastName] = '" & Me!cboFlitLastName & "'"
End If
If Me!NameFlit <> "" Then
If FiltStr = "" Then
FlitStr = "[CITY] = '" & Me!cboFliterCity & "'"
Else
FlitStr = FiltStr & " [CITY] = '" & Me!cboFliterCity & "'"
End If
If Me!NameFilt <> "" Then
FlitStr = "[Oro] = '" & Me!cboFliterOro & "'"
End If
End Sub
The Preview Window
Code:
Option Compare DatabaseOption Explicit
Private Sub cmdNewCase_Click()
DoCmd.Close acForm, "frmClientDetails"
DoCmd.OpenForm "frmErrand", acNormal, "", "", acFormAdd, acDialog
End Sub
Private Sub btnAddErrand_Click()
Dim intID As String
DoCmd.Close acForm, "frmMenu"
DoCmd.Close acForm, "frmClientDetails"
intID = Me!txtID
DoCmd.OpenForm "frmErrandV2", acNormal, "", acFormAdd, OpenArgs:=intID
End Sub
Private Sub btnClose_Click()
DoCmd.Close acForm, "frmClientDetails", acSaveNo
End Sub
Private Sub btnEN_Click()
Me.lblH1.Caption = "Personal data:"
Me.lblClient_ID.Caption = "Client ID:"
Me.lblFirstName.Caption = "First name"
Me.lblLastName.Caption = "Last name"
Me.lblH2.Caption = "Contact information"
Me.lblCity.Caption = "City"
Me.lblAdress.Caption = "Adress"
Me.lblEmail.Caption = "e-mail"
Me.lblHomeNumber.Caption = "Home Number"
Me.lblPhoneNumber.Caption = "Mobile Number"
Me.lblH3.Caption = "Signature"
Me.lblRegisteredOf.Caption = "Registered by"
Me.lblRegisteredDate.Caption = "Registerd on"
Me.btnAddErrand.Caption = "Add Case"
Me.btnSave.Caption = "Save"
Me.btnEdit.Caption = "Edit"
Me.btnDelete.Caption = "Delete"
Me.btnClose.Caption = "Close"
End Sub
Private Sub btnSE_Click()
Me.lblH1.Caption = "Personuppgifter"
Me.lblClient_ID.Caption = "Personnummer"
Me.lblFirstName.Caption = "För Namn"
Me.lblLastName.Caption = "Efter Namn"
Me.lblH2.Caption = "Kontaktuppgifter"
Me.lblCity.Caption = "Post ort"
Me.lblAdress.Caption = "Post Adress"
Me.lblEmail.Caption = "e-mail"
Me.lblHomeNumber.Caption = "Hem Nummer"
Me.lblPhoneNumber.Caption = "Mobil Nummer"
Me.lblH3.Caption = "Signatur"
Me.lblRegisteredOf.Caption = "Registrerades den"
Me.lblRegisteredDate.Caption = "Registrerades av"
Me.btnAddErrand.Caption = "Lägg till ärende"
Me.btnSave.Caption = "Spara"
Me.btnEdit.Caption = "Redigera"
Me.btnDelete.Caption = "Radera"
Me.btnClose.Caption = "Stäng"
End Sub
Private Sub Form_Open(Cancel As Integer)
' MsgBox (Me.OpenArgs)
If Nz(Me.OpenArgs) = 0 Then
'Me.RecordSource = "tblClients"
Else
Me.RecordSource = "SELECT tblClients.* FROM tblClients WHERE (((tblClients.ID)=" & Me.OpenArgs & "));"
End If
' Dim ClintID As String
' ClintID = Me!txtClientID
'
' DoCmd.OpenForm "frmClientSummerySub", acNormal, OpenArgs:=ClintID
Me.txtID.Visible = False
Me.btnEdit.Visible = True
Me.btnSave.Visible = False
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
End Sub
Private Sub btnSave_Click()
If Me.btnSave.Visible = True Then
Me.btnClose.SetFocus
Me.AllowEdits = False
Me.btnSave.Visible = False
Me.btnEdit.Visible = True
End If
End Sub
Private Sub btnEdit_Click()
Me.AllowEdits = True
If Me.btnEdit.Visible = True Then
Me.txtClientID.SetFocus
Me.btnEdit.Visible = False
Me.btnSave.Visible = True
End If
End Sub