Solved

Select query to run on Click of command button

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

Independent Software Vendors: 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 I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

732 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