reult to a text box

D

Dave

Hi

I have the code below on my database. It gives me the highest value in my
table. How do I drop that value into a textbox on screen?

Thanks


Dim rst22 As ADODB.Recordset

Set rst22 = New ADODB.Recordset
With rst22
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open "SELECT Max(InvoiceSum.InvNumber) AS MaxOfInvNumber FROM
InvoiceSum"
End With

rst22.Close
 
M

Michel Walsh

Hi,


That is quite laborious. Before closing the recordset,

Me.TextBoxControl.Value = rst22.Fields(0).Value


It you have been easier to replace all those lines with


Me.TextBoxControl.Value = DMax("InvNumber", "InvoiceSum")


If you still prefer the recordset approach, it is generally faster to
open a firehose cursor:


Me.TextBoxControl.Value=
CurrentProject.Connection.Execute("SELECT MAX(...) ... ").Fields(0).Value




Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top