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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting single field from database and storing into variable.

Status
Not open for further replies.

bfellows

Technical User
Sep 17, 2002
10
US
here's my situation:

I'm looking to snag a field out of a record retrieved by a command executed by the doCmd.RunSQL method or something and then store it in a variable.

this query will only pull one record and i want a single piece of data out of it. any suggestions?

the table structure looks like this:

[ reportID | reportDescription ]

the SQL command i will run:

SELECT reportID from tblDecription WHERE reportDescription = "blahblah"

i want to store reportID (an integer) into an integer variable to use in a procedure i will be writing.

i've ascertained that i'll need to use a recordset - i'm just kinda lost as to where i should start researching...

thanks for any help.
 
aah. i figured it out with the help file (that thing is too useful for its own good).

i ended up using the DLookup method. very useful and quick for picking up a single value from a table or query.

here is the line of code for anyone interested (strName had already been assigned a string from a textbox on the form):

varX = DLookup("[reportID]", "report_description_table", "[reportDesc] = '" & strName & "'")

any comments on this solution?
 
I like that ! But my problem is how to do this for multiple records. What I have is a set of 'readings' for a particular day for 5 types of gasoline. I need to check the 5:00 AM reading with the next reading and so on until the final 5:00 PM reading. There could be 2 readings a day, there could be 10. Sometimes the reading will fluctuate by a gallon or 2 and sometimes it's because they loaded a fuel truck (i.e. 100's of gallons). I need to determine how much was pumped into the truck and how much is due to expansion and contraction.

My dlookup would be : dlookup("Regular","[Tank Inventory]", "[Date] = forms!FormHeader!date")

How do I get the code to look at all of the readings from the day ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top