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

Recordsets!!!!!!!!!

Status
Not open for further replies.

scottian

Programmer
Jul 3, 2003
955
GB
Can anyone tell me why i get an error with this.

All im trying to do is get the top number from a table to a variable to use in an automated e-mail. But i get type mismatch with the msgbox line highlighted.

'===============================
Function TopNum()
Dim Ndb As Database
Dim PNum As Recordset
Dim Nsql As String

PNumsql = "SELECT TOP 1 qryTopNum.NumberField FROM qryMyQuery;"

Set Ndb = CurrentDb()

Set PNum = Ndb.OpenRecordset(Nsql)

MsgBox PNum
End Function

"My God! It's full of stars...
 
You can't throw a recordset object up into a msgbox. You'll need to loop thru the recordset and place values from a field (or multiple fields) from your recordset into the msgbox.
 
MsgBox PNum.Fields(0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Awesome, Thanks PHV.

the msgbox was just to test that the value was passed. If im to use this in a larger function (which will compile an e-mail based on this value) would i still need to use the 'MsgBox PNum.Fields(0)' solution?
Because, the number it returns needs to be referenced from within another SQL statement which is passed to another recordset, which is then (as you stated rjoubert) looped through, concatenating the records to produce an e-mail message body.

"My God! It's full of stars...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top