Hi all,
We are short a couple of staff members in our office since staff members have left our company, I'm not going to lie but I am trying to import the functions of a database created by someone else before I re-joined the company that we don't have much contact with into a database that I created for our company projects to monitor staff exposure into a database I made that created data for all of our project information.
The database that someone else made is full of information that a lot of what is included we don't need & I want to streamline it so only the information that is actually required is included & import it into the database I created, importing only the required information is hopefully going to help make my job a bit easier, I am already working long hours to try & keep on top of what needs to be carried out.
I have been playing around with the code from the original database & I have created a sample database with the information & form I would like to import, I want to have a form like what is included in the sample database that I have uploaded where multiple criteria can be selected from the form "frmExposureReport", the button with the caption "Run Exposure Report" (cmdRun) is pressed & "rptExposureReport" is generated with only the information filtered by the form is included.
The button on the original database is below
	
	
	
		
Also the below code is included
	
	
	
		
I need to modify the code above & get it imported into the attached database so "rptEmployeeExposure" is generated with the required information as our companies 3 monthly or yearly report for each material or project type that I will expand once working with other reports generated using the same method from other tables.
Any help will be appreciated to get the function on the database working
Thanks
PaulD2019
 We are short a couple of staff members in our office since staff members have left our company, I'm not going to lie but I am trying to import the functions of a database created by someone else before I re-joined the company that we don't have much contact with into a database that I created for our company projects to monitor staff exposure into a database I made that created data for all of our project information.
The database that someone else made is full of information that a lot of what is included we don't need & I want to streamline it so only the information that is actually required is included & import it into the database I created, importing only the required information is hopefully going to help make my job a bit easier, I am already working long hours to try & keep on top of what needs to be carried out.
I have been playing around with the code from the original database & I have created a sample database with the information & form I would like to import, I want to have a form like what is included in the sample database that I have uploaded where multiple criteria can be selected from the form "frmExposureReport", the button with the caption "Run Exposure Report" (cmdRun) is pressed & "rptExposureReport" is generated with only the information filtered by the form is included.
The button on the original database is below
		Code:
	
	
	Option Compare Database
Private Sub cmdClear_Click()
    txtName = ""
    txtOther = ""
    txtType = ""
    txtStart = Null
    txtEnd = Null
End Sub
Private Sub cmdClose_Click()
    DoCmd.BrowseTo acBrowseToForm, "frmAnalMain"
End Sub
Private Sub cmdRun_Click()
    Dim StartDate As Date
    Dim EndDate As Date
    Dim rptName As String
    Dim xOther As String
    
    'Set globals and variables for dates
    GBL_Start_Date = Nz(txtStart, #1/1/2001#)
    GBL_End_Date = Nz(txtEnd, #1/1/2099#)
    GBL_Name = Nz(txtName, "")
    GBL_Other = Nz(txtOther, "")
    GBL_Type = Nz(txtType, "")
    GBL_RptTitle = ""
    rptName = txtReport
    xOther = Nz(txtOther, "")
    
    'Check if fields are empty and set variables.
    If Nz(txtStart, "") = "" Then
        StartDate = #1/1/2001#
    Else
        StartDate = Format(txtStart, "mm/dd/yyyy")
    End If
    
    If Nz(txtEnd, "") = "" Then
        EndDate = #1/1/2099#
    Else
        EndDate = Format(txtEnd, "mm/dd/yyyy")
    End If
    
    'Define the report title based on criteria.
    If GBL_Start_Date <> #1/1/2001# Or GBL_End_Date <> #1/1/2099# Or Nz(txtName, "") <> "" Or Nz(txtOther, "") <> "" Then
        If Nz(txtName, "") <> "" Or Nz(txtOther, "") <> "" Or Nz(txtType, "") <> "" Then
            GBL_RptTitle = " For"
            If Nz(txtName, "") <> "" And Nz(txtOther, "") <> "" And Nz(txtType, "") <> "" Then
                GBL_RptTitle = GBL_RptTitle & " " & txtName & " And " & txtOther & " And " & txtType
            ElseIf Nz(txtOther, "") <> "" And Nz(txtType, "") <> "" Then
                GBL_RptTitle = GBL_RptTitle & " " & txtType & " And " & txtOther
            ElseIf Nz(txtName, "") <> "" And Nz(txtOther, "") <> "" Then
                GBL_RptTitle = GBL_RptTitle & " " & txtName & " And " & txtOther
            ElseIf Nz(txtName, "") <> "" And Nz(txtType, "") <> "" Then
                GBL_RptTitle = GBL_RptTitle & " " & txtName & " And " & txtType
            Else
                If Nz(txtName, "") <> "" Then
                    GBL_RptTitle = GBL_RptTitle & " " & txtName
                ElseIf Nz(txtOther, "") <> "" Then
                    GBL_RptTitle = GBL_RptTitle & " " & txtOther
                End If
            End If
        End If
        
        If GBL_Start_Date <> #1/1/2001# And GBL_End_Date <> #1/1/2099# Then
            GBL_RptTitle = GBL_RptTitle & " Between " & GBL_Start_Date & " And " & GBL_End_Date
        Else
            If GBL_Start_Date <> #1/1/2001# Then
                GBL_RptTitle = GBL_RptTitle & " After " & GBL_Start_Date
            ElseIf GBL_End_Date <> #1/1/2099# Then
                GBL_RptTitle = GBL_RptTitle & " Before " & GBL_End_Date
            End If
        End If
    End If
    
    'Run the report based on criteria.
    If rptName Like "*Personal*" Then
        Dim qd As QueryDef
        Set qd = CurrentDb.QueryDefs("qryAnnualsSub")
        qd.sql = "SELECT GetFinYear(Nz([tblProjectActivity].[FinishDate],#01/01/01#)) AS TimePeriod, Sum(-[Audit]) AS AuditCount, Sum(-[tblProjectActivity].[PersonalCarriedOut]) AS PersonalCount, tblProject.ProjectType, tblProjectActivity.Material FROM tblProjectActivity LEFT JOIN tblProject ON tblProjectActivity.ProjectID = tblProject.ProjectID" & _
                   " WHERE(((tblProjectActivity.Notifiable) = True)) And Material Like '*" & xOther & "*' And ProjectType Like '*" & txtType & "*'" & _
                    " GROUP BY GetFinYear(Nz([tblProjectActivity].[FinishDate],#01/01/01#)), tblProject.ProjectType, tblProjectActivity.Material" & _
                     " HAVING (((GetFinYear(Nz([tblProjectActivity].[FinishDate],#01/01/01#))) >= '" & GetFinYear(StartDate) & "' And (GetFinYear(Nz([tblProjectActivity].[FinishDate],#01/01/01#))) <= '" & GetFinYear(EndDate) & "'));"
        
        DoCmd.OpenReport rptName, acViewPreview, , "PersonalName Like '*" & txtName & "*' And PersonalDate Between #" & StartDate & "# And #" & EndDate & "# And Nz(Material,"""") Like '*" & xOther & "*' And ProjectType Like '*" & txtType & "*'"
    ElseIf rptName Like "*Exposure*" Then
        DoCmd.OpenReport rptName, acViewPreview, , "Name Like '*" & txtName & "*' And ItemDate >= #" & StartDate & "# And ItemDate <= #" & EndDate & "# And ProjectType Like '*" & txtType & "*'"
    End If
    
End Sub
	Also the below code is included
		Code:
	
	
	Option Compare Database
Global GBL_Start_Date As Date
Global GBL_End_Date As Date
Global GBL_Name As String
Global GBL_Other As String
Global GBL_Type As String
Global GBL_RptTitle As String
'----Sage login -------------
Global SAGEPath, SAGEPathHAD, SAGECompany, SAGEUser, SAGEpassword As String
Option Explicit
Public Function Get_Global(G_name As String) As Variant
     Select Case G_name
            
            Case "Start_Date"
                    Get_Global = GBL_Start_Date
                    
            Case "End_Date"
                    Get_Global = GBL_End_Date
                    
            Case "GBL_Name"
                    Get_Global = GBL_Name
            
            Case "GBL_Other"
                    Get_Global = GBL_Other
                    
            Case "GBL_Type"
                    Get_Global = GBL_Type
                    
            Case "GBL_RptTitle"
                    Get_Global = GBL_RptTitle
                  
    End Select
    
End Function
	I need to modify the code above & get it imported into the attached database so "rptEmployeeExposure" is generated with the required information as our companies 3 monthly or yearly report for each material or project type that I will expand once working with other reports generated using the same method from other tables.
Any help will be appreciated to get the function on the database working
Thanks
PaulD2019