Solved

Select query to run on Click of command button

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

770 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