Solved

Select query to run on Click of command button

Posted on 2006-07-19
3
139 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

756 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