Trying to get the "Name of Panel" User puts in sheet "TOC" cell A:27, and gets only the 'SQL Query to import Analog Input Tags the user is filtering.

Status
Not open for further replies.

LZ_Code

New Member
Joined
Jan 30, 2025
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Here is the code im working with. Need to figure out how to add code that will look for the "Name of Panel" and filter out the Analog inputs.


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
   
    intID = TOC.[A27]
               
    '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
 
Option Explicit

Sub AnalogInput()

'Get filter name from PAGE
Dim rawFile As String

'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

Dim id As String
id = Worksheets("PAGE").Cells(2, 5).Value = ""

'if a value was entered, open and filter report
If Len(Trim(id)) > 0 Then
' DoCmd.OpenReport "ReportName", acViewPreview, , "[IDENT NO] = " & id, acWindowNormal
End If


'Worksheets("PAGE").Cells(2, 5).Value = ""

'-----If the user entered a panel number then proceed
If Worksheets("PAGE").Cells(2, 5).Value <> "" Then

'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.PLCPanel) = [value needed]) And ((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 If

End Sub
 
Upvote 0
Status
Not open for further replies.

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