Welcome to VBForums
Thread moved from 'Other Programming Languages' forum to the 'Office Development/VBA' forum
First of all create the variable at the top of a module using the keyword Public, eg:
Code:
Public pMyVal as Long
Then add code somewhere to use a recordset to set the value based on a query, eg:
Code:
Dim objRS as ADODB.Recordset
Set objRS = New ADODB.Recordset
objRS.Open "SELECT Max(field) FROM table", CurrentProject.Connection
If Not objRS.EOF Then
pMyVal = objRS.Fields(0).Value
End If
objRS.Close
Set objRS = Nothing