?
Solved

Select query to run on Click of command button

Posted on 2006-07-19
3
Medium Priority
?
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 66

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 66

Accepted Solution

by:
Jim Horn earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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