Getting data from table using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

My name is Branko
I need to get some data from tables that I have already made
For example if my table is Emploeys, I want to get data (as string) from rows Name and Last Name. Then I want to use that strings in other procedures. I have tried so many times to do that and it seem that I don't declare or call things (record or variable) as I should. Could you, please, write that simple VBA code for me and explane to me how I generally declare and call data from tables. I am using Access 2002

Best regards from Belgrade, Serbia.
 
Here is some simple code that opens a recordset based on a table and then
loops through the records to extract data from certain fields:

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strLast As String, strFirst As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TableName", dbOpenDynaset, dbReadOnly)
If rst.BOF = False And rst.EOF = False Then
rst.MoveFirst
Do While rst.EOF = False
strLast = rst.Fields("LastNameFieldName").Value
strFirst = rst.Fields("FirstNameFieldName").Value
' insert code here to do something
' with the two string variables
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing


--
Ken Snell
<MS ACCESS MVP>

bmcvetic said:
Hi,

My name is Branko.
I need to get some data from tables that I have already made.
For example if my table is Emploeys, I want to get data (as string) from
rows Name and Last Name. Then I want to use that strings in other
procedures. I have tried so many times to do that and it seem that I don't
declare or call things (record or variable) as I should. Could you, please,
write that simple VBA code for me and explane to me how I generally declare
and call data from tables. I am using Access 2002.
 
Back
Top