
FindRecord - link main and sub forms with else
I have two sets of code - the first works, the second doesn't. Here's
my problem:
The first set of code works great - it's essentially linking a main form
with a subform on the StudentID. The second set of code almost works -
I'm trying, from the main form, to look for the record with a matching
StudentID, and if there is a matching record in the subform, allow
editing that record, and if there is no matching record, allows creation
of a new record, with the StudentID filled in the relevant field. Any
advice would help!
Rick
First Set of Code:
__________________________________
Private Sub che_Click()
On Error GoTo Err_che_Click
Dim stDocName As String
Dim lngCheck As Long
stDocName = "AddCheckTransaction"
lngCheck = Me!StudentID
DoCmd.OpenForm stDocName, , acLast
DoCmd.GoToRecord , , acNewRec
Forms!AddCheckTransaction!StudentID.DefaultValue = lngCheck
Exit_che_Click:
Exit Sub
Err_che_Click:
MsgBox Err.Description
Resume Exit_che_Click
End Sub
Second Set of Code:
__________________________________________
Private Sub uni_Click()
On Error GoTo Err_uni_Click
Dim stDocName As String
Dim lngUniv As Long
stDocName = "AddUniversityAccount"
lngUniv = Me!StudentID
DoCmd.OpenForm stDocName, , acAll
DoCmd.GoToControl (StudentID)
DoCmd.FindRecord Forms![EnterStudent]![StudentID], acEntire, ,
acSearchAll, , acCurrent, True
If Me!StudentID = lngUniv Then
DoCmd.GoToRecord , , acGoTo
Else
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acNewRec
Forms!AddUniversityAccount!StudentID.DefaultValue = lngUniv
End If
Exit_uni_Click:
Exit Sub