VBA Site contains VBA code to create macros in WORD EXCEL ACCESS OUTLOOK

Option Explicit

Const CONN_STR As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sezam;Data Source=CZC1152H41"
Const txt As String = "test"


Sub PobierzDaneSQL()

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Zrodlo As String
Dim KomZrodlo As Range
Dim KomWynik As Range


On Error GoTo Obsluga
cn.ConnectionString = CONN_STR
cn.Open


Set KomZrodlo = ThisWorkbook.Names("Zrodlo").RefersToRange


Zrodlo = KomZrodlo.Value
rs.Open Zrodlo, cn

'Debug.Print rs.Fields(1).Value

Set KomWynik = ThisWorkbook.Names("Wynik").RefersToRange

KomWynik.CurrentRegion.ClearContents
KomWynik.CopyFromRecordset rs
Dim K As Long, LK As Long
LK = rs.Fields.Count
For K = 0 To LK - 1
KomWynik.Offset(-1, K).Value = rs.Fields(K).Name
Next


KomWynik.CurrentRegion.EntireColumn.AutoFit
KomWynik.Parent.Select

 

Cleaning:
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Exit Sub

Obsluga:
MsgBox Err.Description
Resume Czyszczenie

End Sub

 

 

Getin' values from recordset

Sub MyProc()

Dim db As Database

Dim rst As Recordset

Dim i As Integer

Set db = CurrentDb()

Set rst = db.OpenRecordset("KHM_Kurs_EUR")

Do While Not rst.EOF

Debug.Print rst![Identyfikator] & ", " & rst![kurs] & ", " & rst![datakurs]

If rst![Identyfikator] = i Then

getCourse = rst![kurs]

Exit Sub

End If

rst.MoveNext

Loop

End Sub



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl