+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    08-21-2008
    Location
    Gibraltar
    MS-Off Ver
    Excel 2007
    Posts
    53

    Selection to show in Report Page Header

    Hi ... I'm stumped again !

    What I want to do is to have the dates that have been inputted on a form, appear in the Report page header.

    The form is called Select_Inception. This form only has two text boxes called Start Date and End Date, they select on a field called PeriodFrom. There is also an OK button, this is the vba code I have used

    Code:
    Private Sub cmdOK_Click()
    Dim db As DAO.Database
    Dim QD As QueryDef
    Dim where As Variant
    
    Set db = CurrentDb()
    
    'Delete the existing dynamic query; trap the error if the query does not exist.
    On Error Resume Next
    db.QueryDefs.Delete ("Qry_By_Inception_Date")
    On Error GoTo 0
    
    If Not IsNull(Me![End Date]) Then
        where = where & " AND [PeriodFrom] between DateValue('" + _
        Me![Start Date] + "') AND DateValue('" & Me![End Date] & "')"
    Else
        where = where & " AND [PeriodFrom] >= DateValue('" + Me![Start Date] _
        + "')"
    End If
    
    'MsgBox "Select * from Premium " & ("where " + Mid(where, 6) & ";")
    Set QD = db.CreateQueryDef("Qry_By_Inception_Date", _
    "SELECT * FROM Broker INNER JOIN Premium ON Broker.BrokerNo = Premium.BrokerNo " & (" where " + Mid(where, 6) & ";"))
    
    DoCmd.OpenReport "Premium_by_Inception_Date", acViewPreview
    End Sub
    I've added a text box in the page header of the report and in the control source i've tried this
    Code:
    ="For the period of" & [Forms]![Select_Inception]![Start Date] & "to" & [Forms]![Select_Inception]![End Date]
    But when I open the report I get #Name?

    I'm sure it's something daft I'm doing again.

    Cheers
    Wrightie
    Last edited by wrightie; 06-25-2009 at 12:12 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    233

    Re: Selection to show in Report Page Header

    Well there are 2 ways to do it, the one I would use is using TempVars.

    On the form you enter the dates on make an ok key or something that when clicked does something like:

    Code:
    Private Sub OK_Click()
        Dim MaxBase As Double
        Dim MaxCash As Double
        Dim MaxEarlyOrder As Double
        Dim MaxEarlyShip As Double
        Dim MaxProgram As Double
        Dim MaxDiscount As Double
    
        MaxBase = Nz(Me.MaxBase, 0)
        MaxCash = Nz(Me.MaxCash, 0)
        MaxEarlyOrder = Nz(Me.MaxEarlyOrder, 0)
        MaxEarlyShip = Nz(Me.MaxEarlyShip, 0)
        MaxProgram = Nz(Me.MaxProgram, 0)
        MaxDiscount = (1 - MaxBase) * (1 - MaxCash) * (1 - MaxEarlyOrder) * (1 - (MaxEarlyShip + MaxProgram))
        
        TempVars.Add "MaxBase", MaxBase
        TempVars.Add "MaxCash", MaxCash
        TempVars.Add "MaxEarlyOrder", MaxEarlyOrder
        TempVars.Add "MaxEarlyShip", MaxEarlyShip
        TempVars.Add "MaxProgram", MaxProgram
        TempVars.Add "MaxSeedTenderDiscount", MaxDiscount
        
        Me.Visible = False
    End Sub
    Then in the 2 text fields you enter the following in the control source: =[TempVars]![MaxBase] etc

    These are examples from my database. I use the discounts in the header of a report comparing pricing.

    If the form is still open when you open the report you can always use the "me."

    Hope this helps,

    Dan

    P.S. TempVars only works in Access 2007, (I see you have excel 2007 so assumed.)
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the scales and adding to my reputation, Thanks!

  3. #3
    Registered User
    Join Date
    08-21-2008
    Location
    Gibraltar
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Selection to show in Report Page Header

    Hi Dan ,

    We are on MS 2007 Basic, so for the time being still using Access 2003.
    However I will keep this info for when we get round to upgrading, so thanks for that.

    I don't suppose you have a 2003 option ?

    wrightie

  4. #4
    Registered User
    Join Date
    08-21-2008
    Location
    Gibraltar
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Selection to show in Report Page Header

    I've tried this and get the text "For the period of to" . No error message so it's a tad better !

    ="For the period of" & Forms!Select_Inception![Start Date] & " to" & Forms!Select_Inception![End Date]

  5. #5
    Registered User
    Join Date
    08-21-2008
    Location
    Gibraltar
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Selection to show in Report Page Header

    Yep it worked. This code was ok, i just hadn't placed any dates in the form hence why it was just bringing up only the text.

    ="For the period of" & Forms!Select_Inception![Start Date] & " to" & Forms!Select_Inception![End Date]

    Thanks yet again Dan for you help, I will remember the TempVars for when we upgrade to pro.

    Cheers
    wrightie

  6. #6
    Valued Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    233

    Re: Selection to show in Report Page Header

    Np, glad you figured it out.

    TempVars are a fantastic addition.
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the scales and adding to my reputation, Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0