I have a sime form/subform set up and in the On_Click event on a button on my main form I am trying to append a new records to a subform, requery the subform and then set focus to the new record in the subform. Everything works well except for the set focus part as I can only get it to set focus to the first record in the subform and the the news (i.e. the last) record in the subform. Here is the code for the button:
Any advice on how to make this work is appreciated...
Thanks,
kev
Code:
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim intX As Integer
Dim strNum As String
Dim strUniqueID As String
strNum = 1
strUniqueID = Me.SITEIDMIRROR & "-S" & strNum
If MsgBox("Confirm Add Record for Site ID: " & Forms!frmTOC!subCombo!cmboListSite, vbInformation + vbYesNo, "Confirm Add Record") = vbNo Then
Exit Sub
Else
Set rst = New ADODB.Recordset
strSQL = "SELECT dbo_BAS_SkidPier.UniqueSPID, dbo_BAS_SkidPier.SITEID FROM dbo_BAS_SkidPier WHERE (dbo_BAS_SkidPier.SITEID)='" & Me.SITEIDMIRROR & "'"
rst.Open strSQL, CurrentProject.Connection, adOpenStatic, adLockOptimistic
For intX = 1 To rst.RecordCount
If strUniqueID = rst.Fields("UniqueSPID") Then
strNum = strNum + 1
strUniqueID = Me.SITEIDMIRROR & "-S" & strNum
Else
Exit For
End If
rst.MoveNext
Next intX
End If
rst.Close
Set rst = Nothing
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryAppendSITEID_dbo_BAS_SkidPier"
Forms!frmSkidPierMAIN!frmSkidPierCT.Requery
DoCmd.SetWarnings True
'''PROBLEM AREA OF CODE'''
Forms!frmSkidPierMAIN!frmSkidPierCT.SetFocus
DoCmd.GoToRecord , , acLast
Forms!frmSkidPierMAIN!frmSkidPierCT!UniqueSPID = strUniqueID
Any advice on how to make this work is appreciated...
Thanks,
kev