Solved

Select query to run on Click of command button

Posted on 2006-07-19
3
135 Views
Last Modified: 2010-04-30
I need to know how to get this to work.  I have form with Command Button on it and want to do a select query.  What would be correct syntax?  

Any help would be greatly appreciated!


Private Sub Command0_Click()

SELECT [Contact List].[1st], [Contact List].[2nd], [Contact List].[3rd], [Contact List].[4th], [Contact List].[5th], [Contact List].[First Name], [Contact List].[Last Name]
FROM [Contact List]
WHERE ((([Contact List].[1st]) Is Not Null) AND (([Contact List].[2nd]) Is Null) AND (([Contact List].[3rd]) Is Null) AND (([Contact List].[4th]) Is Null) AND (([Contact List].[5th]) Is Null));

DoCmd.OpenForm "Form1"


End Sub
0
Comment
Question by:ca1358
  • 2
3 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17140053
>I have form with Command Button on it and want to do a select query.
When you say 'do' a select query, does that mean run/display the select query, or use it to populate the form?
0
 

Author Comment

by:ca1358
ID: 17140063
Use if to populate the form.
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 17140145
>DoCmd.OpenForm "Form1"
Are you using Access or VB?  If Access, then just save your SQL as a separate query, then use that query as the RecordSource of your form.

SELECT [1st], [2nd], [3rd], [4th], [5th], [First Name], [Last Name]
FROM [Contact List]
WHERE Not IsNull([1st]) AND Not IsNull([2nd]) AND Not IsNull([3rd]) AND Not IsNull([4th]) AND Not IsNull([5th])
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now