diddydustin
Programmer
Hello everyone. I'm new to this forum.
I'm trying to access the current field on the current record of a form in VBA. I've tried using Me!FieldName and Forms!FormName!FieldName. Every time it only accesses the first record on the form, never the current selected record. The form is basically a front end display for a table, but there is a calender so the user can filter out certain dates. Here is my a segment of my code:
' Set the file handle
Set conn = New ADODB.Connection
' Get the database name.
db_file = "C:\Documents and Settings\Dustin Lyons\Desktop\Network\Driver History.mdb"
' Open a connection.
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
Dim rsMyTable As Recordset
Set rsMyTable = New ADODB.Recordset
rsMyTable.ActiveConnection = conn
rsMyTable.Open "T
ispatch_Miles", , adOpenKeyset, adLockOptimistic, _
adCmdTable
' Find miles by state
Set rs = conn.Execute("SELECT * FROM T:Miles WHERE Route = '" & Forms!Dispatch_Console!Route & "'"
rsMyTable.AddNew
**** here is what it doesn't access the current selected record on the form, but only the first record on the form. I want to access the "Driver" field for the current selected record on the form *****
rsMyTable.Fields("Driver"
.Value = Forms!Dispatch_Console!Driver
*****
rsMyTable.Update
For i = 1 To 15
rsMyTable.Fields(i) = rs.Fields(i).Value + rsMyTable.Fields(i).Value
rsMyTable.Update
Next
rsMyTable.Close
rs.Close
conn.Close
Any info on how to access a field for the current selected record on a form is appreciated. This has been driving me nuts! Thank you!
Dustin
I'm trying to access the current field on the current record of a form in VBA. I've tried using Me!FieldName and Forms!FormName!FieldName. Every time it only accesses the first record on the form, never the current selected record. The form is basically a front end display for a table, but there is a calender so the user can filter out certain dates. Here is my a segment of my code:
' Set the file handle
Set conn = New ADODB.Connection
' Get the database name.
db_file = "C:\Documents and Settings\Dustin Lyons\Desktop\Network\Driver History.mdb"
' Open a connection.
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
Dim rsMyTable As Recordset
Set rsMyTable = New ADODB.Recordset
rsMyTable.ActiveConnection = conn
rsMyTable.Open "T
adCmdTable
' Find miles by state
Set rs = conn.Execute("SELECT * FROM T:Miles WHERE Route = '" & Forms!Dispatch_Console!Route & "'"
rsMyTable.AddNew
**** here is what it doesn't access the current selected record on the form, but only the first record on the form. I want to access the "Driver" field for the current selected record on the form *****
rsMyTable.Fields("Driver"
*****
rsMyTable.Update
For i = 1 To 15
rsMyTable.Fields(i) = rs.Fields(i).Value + rsMyTable.Fields(i).Value
rsMyTable.Update
Next
rsMyTable.Close
rs.Close
conn.Close
Any info on how to access a field for the current selected record on a form is appreciated. This has been driving me nuts! Thank you!
Dustin