Form for user to create custon reports from multiple criteria (1 Viewer)

fvreg

Registered User.
Local time
Yesterday, 23:19
Joined
Sep 15, 2005
Messages
15
I am trying to put together an form to be used in an academic administration database.
Ideally, I would like to create a form that will allow a user to select criteria and get a list of all students fitting that criteria.
For example:
Show me all a) all Economics majors with b) 30-50 Credits who c) have not taken English 101.
All of this data could be compiled into one query, but I would like to create a form that will allow a user to select what data he or she would like to see.
(Maybe they only want to see graduates)
I hope this makes sense.
And I hope someone can help point me in the right direction.

Thank you!
 

Newman

Québécois
Local time
Yesterday, 23:19
Joined
Aug 26, 2002
Messages
766
Maybe this can help you out. (Sorry, I didn't take the time to translate it but I guess you can figure it out. Come back if you need more info about it.)
Code:
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    
    stDocName = "ESuiviSommaire"
    
    'If you use option buttons as criteria...
    VerifierTypeVoute

    'If you use lists as criteria...
    AttacherString stLinkCriteria, VerifierPostes(stLinkCriteria), ""
    
    'If you use dates range as criteria...
    If Not IsNull(txtDateMin) And Not IsNull(txtDateMax) Then
        AttacherString stLinkCriteria, "[DateDebut] >= #" & Me!txtDateMin & "# and [DateDebut] <= #" & Me!txtDateMax & "#", " and "
    Else
        If Not IsNull(txtDateMin) Then AttacherString stLinkCriteria, "[DateDebut] >= #" & Me!txtDateMin & "#", " and "
        If Not IsNull(txtDateMax) Then AttacherString stLinkCriteria, "[DateDebut] <= #" & Me!txtDateMax & "#", " and "
    End If

    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_cmdOK_Click:
    Exit Sub

Err_cmdOK_Click:
    AfficherMessageErreur
    Resume Exit_cmdOK_Click
End Sub

'Utilisation des options choisies dans la liste Postes pour créer le filtre
Private Function VerifierPostes(OldStLink )
    Dim ctlListe As Control
    Dim varElement As Variant
    Dim stLinkCriteria As String

    Set ctlListe = Forms!F_Dialogue_Suivi_Sommaire!lstPostes 'Copie de la liste des postes
    For Each varElement In ctlListe.ItemsSelected 'Tour complet de la liste pour trouver les postes sélectionnés
        AttacherString stLinkCriteria, "[Poste]=""" & ctlListe.ItemData(varElement) & """", " Or "
    Next varElement
    If stLinkCriteria <> "" And OldStLink = "" Then stLinkCriteria = "(" & stLinkCriteria & ")"
    If stLinkCriteria <> "" And OldStLink <> "" Then stLinkCriteria = " or (" & stLinkCriteria & ")"

    VerifierPostes = stLinkCriteria
End Function

Private Function VerifierTypeVoute()
    Dim stLinkCriteria As String
    
    stLinkCriteria = ""

    Select Case fraTypeVoute 'Choix possible sur boutons de radio pour le type de voute
        Case 1
            stLinkCriteria = "500"
        Case 2
            stLinkCriteria = "750"
        Case 3
            stLinkCriteria = "1000"
        Case 4
            stLinkCriteria = "1500"
        Case 5
            stLinkCriteria = "CTE"
    End Select

    If stLinkCriteria <> "" Then VerifierTypeVoute = "[TypeVoute]=" & """" & stLinkCriteria & """"
End Function

Public Sub AttacherString(StringInitial As String, ByVal NouveauString As String, ByVal Separateur As String)
On Error GoTo Err_AttacherString
    
    'Concaténation des "strings" en ajoutant le séparateur, sauf pour le premier "string".
    If StringInitial = "" Then
        StringInitial = NouveauString
    Else
        StringInitial = StringInitial & Separateur & NouveauString
    End If
    
Exit_AttacherString:
    Exit Sub
    
Err_AttacherString:
    AfficherMessageErreur
    Resume Exit_AttacherString
End Sub
 

fvreg

Registered User.
Local time
Yesterday, 23:19
Joined
Sep 15, 2005
Messages
15
This looks promising. However, between my minimal knowledge of VB and the language barrier, I am having a hard time adapting this to my form.
Is there a tutorial somewhere that tells me what each of these steps does?
 

Users who are viewing this thread

Top Bottom