Ok I am very very close now. I figured out that the code needed to be seperated out. So now this is what happens:
Click on a date on the control while in a current record the date gets updated (Not Good: it should either create a new record or go to a record with that date)
When I move to an empty record and click a new date that does not exist it saves the date in the current empty record and moves to a new record. (This is bad because it forces the user to have to navigate back to the previous record)
When I move to an empty record and click on a date that does exist, it always goes to the first record (not good)
Another thing is that I am using the EntryID form the calendar table which is an auto number to navigate to the appropriate record ID. This is bad because what happens when a date is deleted from the calendar table? That would mean the entryIDs are no longer a valid reference to the record ID I want to go to. Please help if you can. Here is the code:
Option Compare Database
Private Sub CalendarCtl_Click()
Dim calendarqry As New Class1
If Me.Dirty = True Then
Me.Dirty = False
End If
Recordqry
End Sub
Private Sub Recordqry()
Dim strSQL As Variant
Dim vart As Variant
strSQL = DLookup("[Datefld]", "Calendartbl", [RepID] = Forms![Scheduling]![RepID_bx] And [Datefld] = [Forms]![Scheduling]![Calendar_subform].[Form]![Date_bx])
If Me!Date_bx <> strSQL Then
DoCmd.GoToRecord , , acNewRec
Else
vart = DLookup("[EntryID]", "Calendartbl", [RepID] = Forms![Scheduling]![RepID_bx] And [Datefld] = [Forms]![Scheduling]![Calendar_subform].[Form]![Date_bx])
If Not IsNull(vart) Then
Entry_ID = vart
End If
DoCmd.GoToRecord , , acGoTo, vart
End If
End Sub
|