Access - calling a form and applying a filter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that selects a project, financial year and repoarting qurter
and then opens a form showing a project and its outputs. I can't get the
form to pick up the project from the first form.

Do I create variables and pass themn as in conventional programing, or what?

YOurs

Tom
 
Based on your description, I'm guessing you have a combo of drop-downs and
text boxes on a lookup form and a command button. To do what you want to
accomplish, you need to use VBA code and it is not too difficult.

Below is a sub that is called when the command button, cmdOK, is clicked.
You can modify this code to fit your needs. If you need more specific help,
post back with your relevant code and questions.

Private Sub cmdOK_Click()

Dim strRep As String
Dim strTitle As String
Dim strFilter As String


'Populate the rep lookup
'
If IsNull(Me.cboRepList.Value) Then
strRep = "Like '*'"
Else
strRep = "=" & Me.cboRepList.Value
End If

'Populate the title lookup
'
If IsNull(Me.txtTitle.Value) Then
strTitle = "Like '*'"
Else
strTitle = "='" & Me.txtTitle.Value & "'"
End If


'Populate the where clause
'
strFilter = "[RepID] " & strRep & " AND [Title] " & strTitle

Debug.Print strFilter
DoCmd.OpenForm "REP_LIST_REF_F", acNormal, , strFilter, acFormEdit,
acWindowNormal
DoCmd.Close acForm, "REP_LOOKUP_F", acSaveNo

End Sub
 
Check Access VB Help on the different arguments of the OpenForm method
(which you use to open the second Form), in particular, the "filter"
argument and the "wherecondition" argument.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top