Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2000 Query - VBA

Status
Not open for further replies.

lynnvictoria

IS-IT--Management
May 2, 2001
12
0
0
US
In Access 2000 I have a query named
qryAllContacts
I have a form named Form1, on Form1 I have a button. In the click event of that button, I would like to open a "filterd" version of the query...WHERE qryAllContacts "CompanyName" and Form1 "CompanyName" are the same.
I want to view all people who work for a particular company.

So, I have this much and don't know squat...please someone help me with syntax....

Public Sub MyThing()

Dim strSQL As String
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Filtered.Open

strSQL = "SELECT * FROM qryAllContacts WHERE ?????(here I get lost....)
Current.Project.Connection
End Sub

Hmmm no life to be thinkin about a thing like this on a Friday Night!
 
In Form1 put companyname in a public variable defined in the standard module. i.e.
Public pubCompanyName as String


strSQL = "SELECT * FROM qryAllContacts WHERE " & _
"companyname = '" & pubCompanyName & "'"

rst.Open strSQL, CurrentProject.Connection, 3, 3

If rst.EOF Then
Msgbox "No records found"
Exit Sub
End If
..... do your processing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top