Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RECORDSET IN ACCESS

Status
Not open for further replies.

alsiru

IS-IT--Management
May 8, 2007
3
DE
Hi all,
First at all saying Im a beginer programing. I would need to read all record from a table one by one untill the end of the file and passing to a variable to use in the screen. I have got to connect to the access DB and insert values in a table but I cant get extract the values from a table to variable.....
Some help would be helpful. Thanks for all.


This is part of the code If have used to insert values into a table.

.......................
Const DBNAME = "C:\Documents and Settings\as05964\My Documents\LINEUP\LINEUPV2.mdb"
Dim connection_string As String, cn As Object, cmd As Object

connection_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBNAME & ";Persist Security Info=False"

Set cn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")

cn.ConnectionString = connection_string
cn.Open
cmd.ActiveConnection = cn

.......

Cadena = Vtam.Screen.getstring(I, 4, 7)
Do Until Cadena = ""
Cadena = Vtam.Screen.getstring(I, 10, 8)
Linea = Cadena
V1 = Vtam.Screen.getstring(I, 50, 7)
V1 = Trim(V1)
V2 = Vtam.Screen.getstring(I, 58, 7)
V2 = Trim(V2)
V3 = Vtam.Screen.getstring(I, 66, 7)
V3 = Trim(V3)
V4 = Vtam.Screen.getstring(I, 74, 7)
V4 = Trim(V4)
Linea = Linea & " " & V1 & " " & V2 & " " & V3 & " " & V4

'Introducción en fichero resultado

strSQL = "insert into Nuevo_Xceif36h (VEHICLE_ID,PACK,SHIP,OPN,CLSE) values ('" & Cadena & "','" & V1 & "','" & V2 & "','" & V3 & "','" & V4 & "')"
cmd.CommandText = strSQL
cmd.Execute
 
Code:
' DB                :  C:\DB.mdb
' DB Table Name     :  Employees
' Employees Field 1 :  FirstName
' Employees Field 2 :  LastName

Sub Main()
   Dim Sys As Object, Sess As Object
   Dim conn As Object, rs As Object, db As String, sql As String

   Set Sys = CreateObject("Extra.System")
   Set Sess = Sys.ActiveSession
   
   Set conn = CreateObject("ADODB.Connection")
   Set rs = CreateObject("ADODB.Recordset")
   
   db = "C:\DB.mdb"
   sql = "Select FirstName, LastName from Employees;"
   
   conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db & ";User Id=admin;Password=;"
   rs.Open sql, conn

   Do Until rs.EOF
      MsgBox rs.Fields("FirstName") & " " & rs.Fields("LastName")
      rs.MoveNext
   Loop

   rs.Close
   conn.Close
   
   Set rs = Nothing
   Set conn = Nothing
   Set Sess = Nothing
   Set Sys = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top