Get value (1 Viewer)

Mihail

Registered User.
Local time
Today, 12:11
Joined
Jan 22, 2011
Messages
2,373
This is my first post heare so...

Hy all !

I know: for you is a very simple question, but for me, a newbe, is unsolved.
Look: I have a table (or a query) with some data.
How extract the value from one cell in a certain field and put it into a vb variabble ? How I "scan" a field cell by cell ?
Hope you understand my english.

Thank you very much !
 

Rabbie

Super Moderator
Local time
Today, 10:11
Joined
Jul 10, 2007
Messages
5,906
Welcome to the forum!

All you need to do is to open a record set containing the data. Then find the required record and then just load the vb variable from the record.fieldname.
 

Mihail

Registered User.
Local time
Today, 12:11
Joined
Jan 22, 2011
Messages
2,373
Thank you for the reply, Rabbie.
I'll work around.

My first problem is the VBA code for Acces, not the logic way.
I "know" VB and VBA for Excel. Now I wish to programme for Acces.
And I need to learn quickly.

Thank you again !
 

Rabbie

Super Moderator
Local time
Today, 10:11
Joined
Jul 10, 2007
Messages
5,906
VBA for Access is identical to VBA for Excel
 

lmonroe

Registered User.
Local time
Today, 02:11
Joined
May 19, 2011
Messages
16
Welcome to the forum!

All you need to do is to open a record set containing the data. Then find the required record and then just load the vb variable from the record.fieldname.

Can you be more specific on how to load a vb variable from a record? I can't seem to figure it out...please help!
 

Mihail

Registered User.
Local time
Today, 12:11
Joined
Jan 22, 2011
Messages
2,373
Imonroe !
One working version (I think is not the best) is:

Code:
Dim DB As DAO.Database
    Set DB = CurrentDb()
Dim SQL As String
    SQL = "YourSQL"
Dim Rst As DAO.Recordset
    Set Rst = DB.OpenRecordset(SQL)

'Or base Rst on a table
    Set Rst = DB.OpenRecordset("TableName")
'Now, assuming you have in Rst a field named "FieldToScan", do the following:
    Rst.MoveFirst
    Do While Not Rst.EOF()
        Debug.Print Rst!FieldToScan
        Rst.MoveNext
    Loop
    Rst.Close
'Clean the memory
    Set Rst = Nothing

Good luck !
 

lmonroe

Registered User.
Local time
Today, 02:11
Joined
May 19, 2011
Messages
16
Hmm...is there any way to do this in a report? I'm just trying to return a single value from a table to show in the report.

More specifically, I want to include in my reports that last day that the database was updated. So if there is another way to do this....
 

Rabbie

Super Moderator
Local time
Today, 10:11
Joined
Jul 10, 2007
Messages
5,906
Write a query to find the latest update date. Open the query with OpenRecordset and then read the value and store in your report.
 

spikepl

Eledittingent Beliped
Local time
Today, 11:11
Joined
Nov 3, 2010
Messages
6,144
I'm just trying to return a single value from a table to show in the report.
use the DLookUp or DMax function to get one value from a table. Look them up in Access documentation
 

lmonroe

Registered User.
Local time
Today, 02:11
Joined
May 19, 2011
Messages
16
Thanks for your help guys! :)

Sounds very useful, but I am having a bit of trouble writing this...

I need it to look in my tblPrioritazationScoreboard
under the column As_of_Date
and return the first value in the column which is a date.

How would I write this with DLookup? I don't understand the arguments very well.
 

boblarson

Smeghead
Local time
Today, 02:11
Joined
Jan 12, 2001
Messages
32,059
and return the first value in the column which is a date.

What do you mean by this? How do you define the first value in the column which is a date? How do you determine which is the first? The first date entered? The earliest date? It matters because data in the tables are not stored in any particular order. You have to have some means to apply order by using a query. The data isn't stored in the table in a first in type of way, even though it may APPEAR to do so. So, that is important to note and understand. When you "open a table" you are not looking at the table but you are looking at a VIEW (or query) of the data (albeit a system query) and there is no order applied. If you use the Sort Order in the table it only affects the view when you open the table to look. It does not affect the actual table data and what happens when you query it out, use it in forms, reports, or formulas.
 

lmonroe

Registered User.
Local time
Today, 02:11
Joined
May 19, 2011
Messages
16
Ah! Sorry for the confusion! The first value in the column is the ONLY cell in the column that contains data. I was just trying to clarify that the data happened to be a date. (shouldn't matter though right?) I hope that clears that up.
 

boblarson

Smeghead
Local time
Today, 02:11
Joined
Jan 12, 2001
Messages
32,059
This should work for you:
Code:
=DMax("[As_of_Date]", "tblPrioritazationScoreboard")
 
Last edited:

Mihail

Registered User.
Local time
Today, 12:11
Joined
Jan 22, 2011
Messages
2,373
This are my first question that ever I asked about Access.
Now I can quote the answer that sent me away from this forum for more than two years:

VBA for Access is identical to VBA for Excel
 

Users who are viewing this thread

Top Bottom