Creating and loading an SQL query using VBA on Access 2007

Posted on 2012-09-17
Last Modified: 2012-09-17
Hi Everyone,

I'm looking to create and load a sql query upon page load using VBA on Access 2007.  The query is a very simple query:

Select *
from TB1
Where TB1.CIF = '5000000'

 Is this doable and if so, can someone please help me by giving me a pseudo code?

Your help is greatly appreciated.

Question by:sarah_siu
    LVL 29

    Accepted Solution

    Do you want this to be the recordsource of the form?  If so you could just add
    Select * from TB1 Where TB1.CIF = "5000000" to the form's RecordSource property.  Or if you wanted to do it by code, in the form's OnLoad event, you would use:
    Me.RecordSource = "Select * from TB1 Where TB1.CIF = '5000000'"

    Open in new window


    Author Comment

    Thanks Irogsinta.  I tried using your code in the code builder for my form.  It accepted the code fine but no data is displayed after I refresh the page...
    LVL 29

    Expert Comment

    You do have bound textboxes in your form, right?

    Author Comment

    I have nothing on my form.  it's a completely blank slate...
    LVL 29

    Assisted Solution

    Sounds like you're not that familiar with Access.  In your case, why not try selecting your table in the Navigation pane on the left and then use one of the form wizards to help you.
    Create Form

    Author Closing Comment

    You learn something new everyday.  Thanks for the quick turnaround and help!

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    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…

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now