SlideShare a Scribd company logo
VBA case studies
This document outlines parts of some of the VBA projects completed. Get
in touch if you need help with a new or existing Excel or Access application.
Example VBA projects
Access updates
The client wanted updates to the invoice and delivery note in Access. They
wanted it to reflect the invoice they see from their accounting package.
They also wanted payment details in the footer.
The client also wanted to add a delivery address so fields were added to
the existing form in Access and the existing queries updated.
SQL Queries
SQL queries can be written to create, read, update and delete data in
Access.
Access can be used as a back end for Excel. It is also possible to use other
databases like mySQL or MSSQL as a backend for Access/Excel. These
can be run on a PC or Mac. For example there is a mySQL driver for Mac.
An ODBC connection can be set up on Mac.
Mac compatibility
The client wanted the ability to run their existing Excel workbook on Mac.
This involves replacing all of the ActiveX controls with form controls and
updating the code.
Buttons and checkboxes were replaced here:
Generating a code using existing data
For the policy tracking database the client wanted an auto code number
generated when both comboboxes had been selected.
The following function was written to check the records in the database and
generate the fields:
Sub SetCode()
'Check if both comboboxes have values before generating
code
If IsNull(Me.PolicyManualCombo.Column(1)) Then
Exit Sub
End If
If IsNull(Me.PolicySectionCombo.Column(1)) Then
Exit Sub
End If
'Get policy manual section value from combobox
Dim policyManualValue As String
policyManualValue = Me.PolicyManualCombo.Column(1)
'Get this policy section combo
Dim PolicySectionComboValue As String
PolicySectionComboValue =
Me.PolicySectionCombo.Column(1)
'Instantiate DB and Recordset
Dim databaseRef As DAO.Database
Dim ManualIdRs As DAO.Recordset
'Set DB
Set databaseRef = CurrentDb
'Query the Manual ID number by selected abbr in
combobox
Set ManualIdRs = databaseRef.OpenRecordset("SELECT
Manual_T.ManualID FROM Manual_T WHERE [ManualAbbr] = '" _
& policyManualValue & "'",
dbOpenDynaset)
'Declare selected manualID variable
Dim PolicyManualId As Integer
'Loop populated recordset and assign ManualId value to
variable
Do While Not ManualIdRs.EOF
PolicyManualId = ManualIdRs("ManualID")
ManualIdRs.MoveNext
Loop
'Setup section ID recordset
Dim SectionIdRs As DAO.Recordset
'Query the Section ID number by selected abbr in
combobox
Set SectionIdRs = databaseRef.OpenRecordset("SELECT
Section_T.SectionID FROM Section_T WHERE [SectionAbbr] = '"
_
& PolicySectionComboValue &
"'", dbOpenDynaset)
'Loop populated recordset and assign SectionId value to
variable
Do While Not SectionIdRs.EOF
PolicySectionId = SectionIdRs("SectionID")
SectionIdRs.MoveNext
Loop
' Concatenate and create new code
Dim concatedVersion As String
concatedVersion = policyManualValue + "-" +
PolicySectionComboValue
'Setup policydata recordset
Dim PolicyDataRs As DAO.Recordset
'Query all matching PolicyData records filter by
SectionId and ManualId
Set PolicyDataRs = databaseRef.OpenRecordset("SELECT
PolicyData_T.PolicyCode, PolicyData_T.PolicySection,
PolicyData_T.PolicyManual FROM PolicyData_T WHERE
[PolicySection] = " _
& PolicySectionId & " And [PolicyManual] = " &
PolicyManualId, dbOpenDynaset)
'Count number of records for above filter. Add one to
generate new Id.
Dim newRecordNumber As Integer
newRecordNumber = PolicyDataRs.RecordCount + 1
'Format new id to 3 digits
Dim numberOfRecords As String
numberOfRecords = CStr(Format(newRecordNumber, "000"))
'Create new code by concatenating both codes, hyphens
and the new Id
Dim code As String
code = concatedVersion + "-" + numberOfRecords
'Fill code and check if it needs adding to the database
Me.PolicyCodeCombo.Value = code
End Sub

More Related Content

Similar to VBA work.pdf

PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)
Buck Woolley
 
Has Many And Belongs To Many
Has Many And Belongs To ManyHas Many And Belongs To Many
Has Many And Belongs To Many
guest80d303
 
has_many_and_belongs_to_many
has_many_and_belongs_to_manyhas_many_and_belongs_to_many
has_many_and_belongs_to_many
tutorialsruby
 
has_many_and_belongs_to_many
has_many_and_belongs_to_manyhas_many_and_belongs_to_many
has_many_and_belongs_to_many
tutorialsruby
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
todd331
 

Similar to VBA work.pdf (20)

PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastore
 
Lecture13
Lecture13Lecture13
Lecture13
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Has Many And Belongs To Many
Has Many And Belongs To ManyHas Many And Belongs To Many
Has Many And Belongs To Many
 
Olap
OlapOlap
Olap
 
has_many_and_belongs_to_many
has_many_and_belongs_to_manyhas_many_and_belongs_to_many
has_many_and_belongs_to_many
 
has_many_and_belongs_to_many
has_many_and_belongs_to_manyhas_many_and_belongs_to_many
has_many_and_belongs_to_many
 
Tony Von Gusmann & MS BI
Tony Von Gusmann & MS BITony Von Gusmann & MS BI
Tony Von Gusmann & MS BI
 
MAD UNIT 5 FINAL.pptx
MAD UNIT 5 FINAL.pptxMAD UNIT 5 FINAL.pptx
MAD UNIT 5 FINAL.pptx
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
Rodney Matejek Portfolio
Rodney Matejek PortfolioRodney Matejek Portfolio
Rodney Matejek Portfolio
 
At the core you will have KUSTO
At the core you will have KUSTOAt the core you will have KUSTO
At the core you will have KUSTO
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
 
B_110500002
B_110500002B_110500002
B_110500002
 
Mdx complex-queries-130019
Mdx complex-queries-130019Mdx complex-queries-130019
Mdx complex-queries-130019
 
MS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithmMS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithm
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

VBA work.pdf

  • 1. VBA case studies This document outlines parts of some of the VBA projects completed. Get in touch if you need help with a new or existing Excel or Access application. Example VBA projects Access updates The client wanted updates to the invoice and delivery note in Access. They wanted it to reflect the invoice they see from their accounting package. They also wanted payment details in the footer.
  • 2. The client also wanted to add a delivery address so fields were added to the existing form in Access and the existing queries updated. SQL Queries SQL queries can be written to create, read, update and delete data in Access. Access can be used as a back end for Excel. It is also possible to use other databases like mySQL or MSSQL as a backend for Access/Excel. These can be run on a PC or Mac. For example there is a mySQL driver for Mac. An ODBC connection can be set up on Mac.
  • 3.
  • 4. Mac compatibility The client wanted the ability to run their existing Excel workbook on Mac. This involves replacing all of the ActiveX controls with form controls and updating the code. Buttons and checkboxes were replaced here: Generating a code using existing data For the policy tracking database the client wanted an auto code number generated when both comboboxes had been selected.
  • 5. The following function was written to check the records in the database and generate the fields: Sub SetCode() 'Check if both comboboxes have values before generating code If IsNull(Me.PolicyManualCombo.Column(1)) Then Exit Sub End If If IsNull(Me.PolicySectionCombo.Column(1)) Then Exit Sub End If 'Get policy manual section value from combobox Dim policyManualValue As String policyManualValue = Me.PolicyManualCombo.Column(1) 'Get this policy section combo Dim PolicySectionComboValue As String PolicySectionComboValue = Me.PolicySectionCombo.Column(1) 'Instantiate DB and Recordset Dim databaseRef As DAO.Database Dim ManualIdRs As DAO.Recordset
  • 6. 'Set DB Set databaseRef = CurrentDb 'Query the Manual ID number by selected abbr in combobox Set ManualIdRs = databaseRef.OpenRecordset("SELECT Manual_T.ManualID FROM Manual_T WHERE [ManualAbbr] = '" _ & policyManualValue & "'", dbOpenDynaset) 'Declare selected manualID variable Dim PolicyManualId As Integer 'Loop populated recordset and assign ManualId value to variable Do While Not ManualIdRs.EOF PolicyManualId = ManualIdRs("ManualID") ManualIdRs.MoveNext Loop 'Setup section ID recordset Dim SectionIdRs As DAO.Recordset 'Query the Section ID number by selected abbr in combobox Set SectionIdRs = databaseRef.OpenRecordset("SELECT Section_T.SectionID FROM Section_T WHERE [SectionAbbr] = '" _ & PolicySectionComboValue & "'", dbOpenDynaset) 'Loop populated recordset and assign SectionId value to
  • 7. variable Do While Not SectionIdRs.EOF PolicySectionId = SectionIdRs("SectionID") SectionIdRs.MoveNext Loop ' Concatenate and create new code Dim concatedVersion As String concatedVersion = policyManualValue + "-" + PolicySectionComboValue 'Setup policydata recordset Dim PolicyDataRs As DAO.Recordset 'Query all matching PolicyData records filter by SectionId and ManualId Set PolicyDataRs = databaseRef.OpenRecordset("SELECT PolicyData_T.PolicyCode, PolicyData_T.PolicySection, PolicyData_T.PolicyManual FROM PolicyData_T WHERE [PolicySection] = " _ & PolicySectionId & " And [PolicyManual] = " & PolicyManualId, dbOpenDynaset) 'Count number of records for above filter. Add one to generate new Id. Dim newRecordNumber As Integer newRecordNumber = PolicyDataRs.RecordCount + 1 'Format new id to 3 digits Dim numberOfRecords As String numberOfRecords = CStr(Format(newRecordNumber, "000"))
  • 8. 'Create new code by concatenating both codes, hyphens and the new Id Dim code As String code = concatedVersion + "-" + numberOfRecords 'Fill code and check if it needs adding to the database Me.PolicyCodeCombo.Value = code End Sub