Calling Data from access based on a specific name in TOC cell A:27

LZ_Code

New Member
Joined
Jan 30, 2025
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Bellow is what I have so far. I am calling in query Analog Inputs, but need to specifically call Analog Input from Sheet 'TOC' cell A27 which will be PLCPanel.


VBA Code:
Option Explicit

Sub AnalogInput_DB()

    'Path
    Dim strPath As String
   
    'Provider
    Dim strProv As String
   
    'Connection String
    Dim strCn As String
   
    'Connection
    Dim Cn As New Connection
                 
    'RecordSet for AI
    Dim rsQry_AI As New Recordset
   
    'SQL Query for AI
    Dim strQry_AI As String
   
   
    'Establish connection to Project DB. Looks at the filepath specified in cell B1 of Project_DB Sheet
   strPath = ActiveWorkbook.Sheets("PAGE").Range("B1").Text
    strProv = "Microsoft.ACE.OLEDB.12.0;"
   strCn = "Provider=" & strProv & "Data Source=" & _
   strPath

    'Connection Open
   Cn.Open strCn
              
    'SQL Query to import Digital Input Tags
   strQry_AI = "SELECT Instruments.PLCPanel, Instruments.Address FROM Instruments WHERE (((Instruments.AnalogInput)=True)) ORDER BY Instruments.PLCPanel;"
   rsQry_AI.Open strQry_AI, Cn
   
    'Puts Data into the Device Column of the Digital Device Sheet
   ActiveWorkbook.Sheets("AnalogInput").Range("A17").CopyFromRecordset rsQry_AI
   
    Cn.Close
   

End Sub
 
It worked I fixed the error it was giving me. see the small changes i did. it worked thank you so much!
The required change has been already explained in the provided code, so it is not a fix but setting.
The marked solution has been changed accordingly.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,226,480
Messages
6,191,253
Members
453,649
Latest member
jtc19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top