Creating queries

Tawcan

Registered User.
Local time
Today, 00:29
Joined
Mar 19, 2003
Messages
58
Does anyone know how I could automatically create queries with different criterias when a button on the database (form) is clicked?

I think you need to do some VB coding, but I'm clueless.... :o
 
Article ID: Q95931

or search here, there have been many examples posted
 
Link please.... :)

Don't know how you can search post ID's.
 
Found it. :D
http://support.microsoft.com/default.aspx?scid=kb;en-us;95931

Hmmm few more questions.

On the article it says create a query form.... but in step 2 it says create the following new form that is not based on any table or query.... O_o I guess they meant create it in form?

Right now for the button on my form I have the following code:

'VIEW REPORT button.
'Opens student's APR table in 'report' format.

Private Sub Label8_Click()
On Error GoTo ErrorHandler
If (IsNull(Me!Box2)) Then
MsgBox ("Please first select a student by clicking on GET STUDENT or browsing through the STUDENT LIST.")
Exit Sub
End If

DoCmd.OpenReport "REPORT 1 (Bob)", acViewPreview *
Exit Sub

ErrorHandler:
MsgBox Error(Err)
Exit Sub

End Sub

do I just add OnClick: QBF_Macro after the * line?


Don't quite understand this following code either...

Query: QBF_Query
---------------------------------------------------------
Field: CustomerID
Sort: Ascending
Criteria: Forms![QBF_Form]![What Customer ID] Or _
Forms![QBF_Form]![What Customer ID] Is Null
Field: EmployeeID
Sort: Ascending
Criteria: Forms![QBF_Form]![What Employee ID] Or _
Forms![QBF_Form]![What Employee ID] Is Null
Field: OrderID
Field: OrderDate

The fields are what's in the query.... but for the criterias I don't understand how you create them. Say I have a table that displays bunch data in record. So I have a field called YEAR. If i want to display only YEAR 1, under criteria, can I just do

Criteria: "1"
Like what you would do normally?


Thanx for the helps. :)
 
Here's an example from one of my simpler selection forms. I've also included a picture of the form so the example will be easier to understand.

Code:
Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

    Dim strDocName As String
    Dim PrintMode As Integer
    Dim strWhere As String
    
    If Me.fraPrintOption = 2 Then
        PrintMode = acNormal
    Else
        PrintMode = acPreview
    End If
    
    If Me.fraReportName = 1 Then
        strDocName = "rptSPIPdetail"
        strWhere = "ProjectID = " & Me.cmbProjectVersion
    Else
        strDocName = "rptSPIP"
        strWhere = ""
    End If
    
    DoCmd.OpenReport strDocName, PrintMode, , strWhere
    
Exit_cmdPreview_Click:
    Exit Sub

Err_cmdPreview_Click:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_cmdPreview_Click
    
End Sub
 

Attachments

  • selection.jpg
    selection.jpg
    17.8 KB · Views: 135
Pat Hartman said:
Here's an example from one of my simpler selection forms. I've also included a picture of the form so the example will be easier to understand.

Code:
Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

    Dim strDocName As String
    Dim PrintMode As Integer
    Dim strWhere As String
    
    If Me.fraPrintOption = 2 Then
        PrintMode = acNormal
    Else
        PrintMode = acPreview
    End If
    
    If Me.fraReportName = 1 Then
        strDocName = "rptSPIPdetail"
        strWhere = "ProjectID = " & Me.cmbProjectVersion
    Else
        strDocName = "rptSPIP"
        strWhere = ""
    End If
    
    DoCmd.OpenReport strDocName, PrintMode, , strWhere
    
Exit_cmdPreview_Click:
    Exit Sub

Err_cmdPreview_Click:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_cmdPreview_Click
    
End Sub


Hmmm? :confused: :confused: :confused:
 
??

I wonder what post I thought I was responding to.
 

Users who are viewing this thread

Back
Top Bottom