reult to a text box

  • Thread starter Thread starter Dave
  • Start date Start date
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
 
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
 
Back
Top