Results 1 to 2 of 2
  1. #1
    amonadi is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    2

    Unhappy need some example

    Hi I'm trying to build a very simple report. I have a lookup table (value,id) and another table with some data that maps to lookup.

    I'd like to make a report where a user can select from drop down menu and type in a text box then press submit to see the result of a query to my data table.



    I know how to make a report from the wizard and i played around with adding selection box and text box.. etc. However, I have no clue where to start with code required for button to reach a generated report.

    Can someone direct me to a tutorial or kindly provide me with a sample code. I'm a little familiar with VB if i have something to start with i'm sure I can mold it to what i want.

    Thanks you!

  2. #2
    viper is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    26
    Here is a sample of how I set up a database to display a report based on a range of dates (start date then end date). I created a form with unbound text boxes with a button marked submit then added the following code

    Code:
    Option Explicit
    Private Sub Form_Open(Cancel As Integer)
      Me.Caption = Forms![Report Date Range].OpenArgs
    End Sub
    Private Sub Submit_Click()
      If IsNull([Beginning Order Date]) Or IsNull([Ending Order Date]) Then
          MsgBox "You must enter both beginning and ending dates."
          DoCmd.GoToControl "Beginning Order Date"
      Else
          If [Beginning Order Date] > [Ending Order Date] Then
              MsgBox "Ending date must be greater than Beginning date."
              DoCmd.GoToControl "Beginning Order Date"
          Else
              Me.Visible = False
          End If
      End If
    End Sub
    Then in the report make sure that the fields match the criteria your entering in the form that you created. Once you've created the report add the following code to the report.

    Code:
    Option Explicit
    Private Sub Report_NoData(Cancel As Integer)
      MsgBox "There is no data for this report. Canceling report..."
      Cancel = -1
    End Sub
    Private Sub Report_Close()
      DoCmd.Close acForm, "Report Date Range"
    End Sub
    Private Sub Report_Open(Cancel As Integer)
      DoCmd.OpenForm "Report Date Range", , , , , acDialog, "Range Logs"
    End Sub
    Now I had 3 different reports that pulled information from 3 different tables but had a date range associated with them. I was able to use the same code on all three reports using the same form I created to input the criteria.

    The code was created with date range in mind but I’m sure you can adapt it so that you can enter in any kind of data to pull specific information for a report.

    Regards, Viper

Please reply to this thread with any new information or opinions.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums