Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Command Button and macros executing report (2003)

    Hi!, I having a little problem figuring this out. I have a command button that pulls a report depending on the value on an unbound combo box. I am using a macro to execute the command. I will like the command button to pull all the records if no selection is chosen from the unbound combo box.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button and macros executing report (2003)

    I almost never use macros, I find VBA code much easier to debug and to maintain. VBA code for the command button could look like this - you'll have to substitute the correct names, obviously.

    Private Sub cmdReport_Click()
    Dim strWhere As String

    If Not IsNull(Me.cboSomething) Then
    strWhere = "[FieldName] = " & Me.cboSomething
    End If

    DoCmd.OpenReport ReportName:="rptMyReport", View:=acViewPreview, WhereCondition:=strWhere
    End Sub

    The above assumes that FieldName is a number field. If it is a text field, use

    strWhere = "[FieldName] = " & Chr(34) & Me.cboSomething & Chr(34)

    and if it is a date field, use

    strWhere = "[FieldName] = #" & Format(Me.cboSomething, "mm/dd/yyyy") & "#"

  3. #3
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Command Button and macros executing report (2003)

    thank again hans.

Posting Permissions

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