Skip to content

Commit

Permalink
add access query def
Browse files Browse the repository at this point in the history
  • Loading branch information
areed1192 committed Dec 29, 2020
1 parent babb681 commit 0fd9cec
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 18 deletions.
61 changes: 44 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,61 @@ Support Sigma Coding

## Overview

Howdy! My name is [Alex](https://www.linkedin.com/in/alex-reed/), and if you're like me, you enjoy the world of programming. Or maybe you were like me a few years ago and are beginning to take your first step into this exciting world. The GitHub repository you're currently contains almost all of the code you find on my YouTube channel Sigma Coding. Feel free to clone, download or branch this repository so you can leverage the code I share in my channel.
Howdy! My name is [Alex](https://www.linkedin.com/in/alex-reed/), and if you're like me, you
enjoy the world of programming. Or maybe you were like me a few years ago and are beginning
to take your first step into this exciting world. The GitHub repository you're currently contains
almost all of the code you find on my YouTube channel Sigma Coding. Feel free to clone,
download or branch this repository so you can leverage the code I share in my channel.

Because I cover so many different langages on my YouTube channel, I dedicate a folder to each specific lanaguge. Right now, I cover the following lanagues on my channel:
Because I cover so many different langages on my YouTube channel, I dedicate a folder to each
specific lanaguge. Right now, I cover the following lanagues on my channel:

- [Python](https://github.com/areed1192/sigma_coding_youtube/tree/master/python)
- [VBA](https://github.com/areed1192/sigma_coding_youtube/tree/master/vba)
- [JavaScript](https://github.com/areed1192/sigma_coding_youtube/tree/master/javascript)
- [M Langauge (Used for Power Query & Power BI)](https://github.com/areed1192/sigma_coding_youtube/tree/master/m%20language)
- [T SQL](https://github.com/areed1192/sigma_coding_youtube/tree/master/t%20sql)

This list is continuously changing, and I do my best to make tutorials engaging, exciting, and most importantly, easy to follow!
This list is continuously changing, and I do my best to make tutorials engaging, exciting,
and most importantly, easy to follow!

## Topics

Now, I cover a lot of topics on my channel and as much I would like to list them all I don't want to overload with you a bunch of information. Here is a list of some of my more popular topics:
Now, I cover a lot of topics on my channel and as much I would like to list them all I don't
want to overload with you a bunch of information. Here is a list of some of my more popular topics:

- **Python:**

- **Win32COM** The Win32COM library allows us to control the VBA object model from Python.
- **TD Ameritrade API** The TD Ameritrade API allows us to stream real-time quote data and execute trades from Python.
- **Interactive Brokers API** The TD Ameritrade API allows us to stream real-time quote data and execute trades from Python.
- **Machine Learning** I cover different machine learning models ranging from regression to classification.
- **Pythonnet** Pythonnet is used to connect Python to something called the CLR (Common Language Runtime) which gives us access to more Windows speicific libraries.
- **TD Ameritrade API** The TD Ameritrade API allows us to stream real-time quote data and
execute trades from Python.
- **Interactive Brokers API** The TD Ameritrade API allows us to stream real-time quote data
and execute trades from Python.
- **Machine Learning** I cover different machine learning models ranging from regression to
classification.
- **Pythonnet** Pythonnet is used to connect Python to something called the CLR (Common Language
Runtime) which gives us access to more Windows speicific libraries.

- **VBA:**

- **PowerPoint VBA** This series covers interacting with PowerPoint objects using VBA, topics like linking OLE objects and formatting slides.
- **Word VBA** With Word VBA, we see how to manipulate different documents and change the underlying format in them.
- **Outlook VBA** In Outlook, we work with email objects and account information.
- **Access VBA** In Access, we can store large amounts of data. With Access, we will see how to
create tables, query existing tables, and even importing and exporting data to and from access.
- **Excel VBA** In Excel, we do an awful lot even working with non-standard libraries like ADODB.
- **Outlook VBA** In Outlook, we work with email objects and account information.
- **PowerPoint VBA** This series covers interacting with PowerPoint objects using VBA, topics like
linking OLE objects and formatting slides.
- **Publisher VBA** In Publisher, we explore how to create fliers and other media documents for
advertising.
- **Word VBA** With Word VBA, we see how to manipulate different documents and change the underlying
format in them.

- **JavaScript:**

- **Office API** Learn how to use the new JavaScript API for Microsoft Office.
- **Excel API** The Excel API focuses just on the API for Microsoft Excel and the object model associated with it.
- **Word API** The Word API focuses just on the API for Microsoft Word and the object model associated with it.
- **Excel API** The Excel API focuses just on the API for Microsoft Excel and the object
model associated with it.
- **Word API** The Word API focuses just on the API for Microsoft Word and the object model
associated with it.

- **TSQL:**

Expand All @@ -82,11 +101,14 @@ Now, I cover a lot of topics on my channel and as much I would like to list them

## Resources

If you ever have a question, would like to suggest a topic, found a mistake or just want some input for a project you can always email me at **[email protected]**. Additionally, you can find dedicated folders in the repository for resources like documentation.
If you ever have a question, would like to suggest a topic, found a mistake or just want some
input for a project you can always email me at **[email protected]**. Additionally, you
can find dedicated folders in the repository for resources like documentation.

## Links To Other Respositories

Some of my projects are so large that they have dedicated repositories for them. Here is a list of repositiories of my other repositiories:
Some of my projects are so large that they have dedicated repositories for them. Here is a
list of repositiories of my other repositiories:

- [TD Ameritrade API Client For Python](https://github.com/areed1192/td-ameritrade-python-api)
- [Interactive Brokers API Client For Python](https://github.com/areed1192/interactive-broker-python-api)
Expand All @@ -97,10 +119,15 @@ Some of my projects are so large that they have dedicated repositories for them.
## Support the Channel

**Patreon:**
If you like what you see! Then Help support the channel and future projects by donating to my **[Patreon Page](https://www.patreon.com/sigmacoding)**. I'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require me to pay monthly fees.
If you like what you see! Then Help support the channel and future projects by donating to
my **[Patreon Page](https://www.patreon.com/sigmacoding)**. I'm always looking to add more
content for individuals like yourself, unfortuantely some of the APIs I would require me to
pay monthly fees.

**Hire Me:**
If you have a project, you think I can help you with feel free to reach out at [[email protected]](mailto:[email protected]?subject=[GitHub]%20Project%20Proposal) or fill out the [contract request form](https://forms.office.com/Pages/ResponsePage.aspx?id=ZwOBErInsUGliXx0Yo2VfcCSWZSwW25Es3vPV2veU0pUMUs5MUc2STkzSzVQMFNDVlI5NjJVNjREUi4u)

**Disclosures:**
I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to **Amazon.com**. Full Disclosure: I will earn a commission if you purchase from the Shop Amazon link, more details are provided below.
I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program
designed to provide a means for sites to earn advertising fees by advertising and linking to **Amazon.com**.
Full Disclosure: I will earn a commission if you purchase from the Shop Amazon link, more details are provided below.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
# Cell1.Value = 3000
# Cell2.Value = 4000

# End Sub
# End Sub
110 changes: 110 additions & 0 deletions vba/vba-access/query-definitions.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Option Compare Database

Sub WorkWithQueries()

'Declare our variables.
Dim AccessApp As Application
Dim AccessDatabase As Database
Dim AccessTable As TableDef
Dim AccessQuery As QueryDef
Dim AccessRecord As Recordset
Dim AccessRecordClone As Recordset
Dim QueryDefName As String

'Grab the access application.
Set AccessApp = Application

'Grab the Current Database in our application.
Set AccessDatabase = AccessApp.CurrentDb

QueryDefName = "PullStockPricesTest"

'Call the `IsInCollection` to see if the QueryDefinition Object Exists.
If IsInCollection(ObjectName:=QueryDefName, CollectionToCheck:=AccessDatabase.QueryDefs) = False Then

'If it doesn't create a new query definition.
Set AccessQuery = AccessDatabase.CreateQueryDef(Name:=QueryDefName, SQLText:="SELECT * FROM StockPrices")

'Refresh the QueryDefs Collection.
AccessDatabase.QueryDefs.Refresh

'Refresh the main Database Window.
AccessApp.RefreshDatabaseWindow

Else

'If it does exist, then grab it from the query definitions collection.
Set AccessQuery = AccessDatabase.QueryDefs(QueryDefName)

End If

'Grab when it was last updated.
Debug.Print AccessQuery.LastUpdated

'Grab the SQL Command.
Debug.Print AccessQuery.SQL

'We can even update the SQL Statement after creating a Def.
AccessQuery.SQL = "SELECT * FROM StockPrices ORDER BY date DESC"

'Is it Updatable?
Debug.Print AccessQuery.Updatable

'Once you've defined the query you can open a new recordset.
Set AccessRecord = AccessQuery.OpenRecordset

'Print out the number of records.
Debug.Print "There are " + CStr(AccessRecord.RecordCount) + " records."

'Start working with the recordset object.
With AccessRecord

'As long as their is a record keep going.
Do Until .EOF

'Print out the first column.
Debug.Print ![Date]
Debug.Print ![Close]

'VERY IMPORTANT!!!! IF YOU MISS THIS YOU WILL HAVE A NEVER ENDING LOOP
.MoveNext

Loop

End With

'Clone the Record.
Set AccessRecordClone = AccessRecord.Clone
Debug.Print "Cloned Record Count is: " + CStr(AccessRecordClone.RecordCount)

'Close the Recordset object.
AccessRecord.Close

End Sub


Function IsInCollection(ObjectName As String, CollectionToCheck As Object)

'Declare Variable.
Dim CollectionObject As Object
Dim WasFound As Boolean

'Loop through the "Collection".
For Each CollectionObject In CollectionToCheck

'If the Name matches, it means we have a match.
If CollectionObject.Name = ObjectName Then
WasFound = True
End If

Next

'If it was found we are good.
If WasFound <> True Then
WasFound = False
End If

'Otherwise we don't have a match.
IsInCollection = WasFound

End Function

0 comments on commit 0fd9cec

Please sign in to comment.