LarryDeLaruelle
Technical User
I have a sub form with a command button to save.
On Click I run some code to concantenate the selections made in a list box and a DLookup to get another needed data item.
I then have a DoCmd.GoToRecord , , acNewRec which errors and tells me that I may be at the end of the recordset.
However, I added another command button to the form to add a record using the same DoCmd.GoToRecord , , acNewRec and rem'ed out the line in the Save event. That works fine.
I've also tried to explicitly save the record prior to the NewRec but that doesn't seem to have any effect.
Any idea what could be causing this? Here is the code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim intLoop As Integer
Dim intRecCnt As Integer
Dim intNumTimes As Integer
'Creates the string for Dosage Times -- stored in DosageTime
intNumTimes = lstTimes.ListCount
For intLoop = 0 To intNumTimes
If lstTimes.Selected(intLoop) = True Then
intRecCnt = intRecCnt + 1
If intRecCnt = 1 Then
DosageTimes = lstTimes.Column(0, intLoop)
Else
DosageTimes = DosageTimes & ", " & lstTimes.Column(0, intLoop)
End If
End If
Next intLoop
'If no times are selected, then a message is displayed to the user requesting a selection.
If intRecCnt = 0 Then
MsgBox "You must select at least one dosage time!", vbOKOnly + vbCritical, "TCC Medical Database"
lstTimes.SetFocus
Exit Sub
End If
'This code identifies the current location of the resident and stores that value in LocationID
LocationID = DLookup("LocationID", "ClientLocation", "ClientID = " _
& Forms!frmMedHistoryInput.cboSelect _
& " AND EndDate Is Null"
DoCmd.GoToRecord , , acNewRec
Forms!frmMedHistoryInput!frmMedHistUpdateSub.Requery
Forms!frmMedHistoryInput!cmdLetter.Enabled = True
frmMedHistoryInput is the main form; frmMedHistUpdateSub is another subform on the main. I want to trigger the requery after the NewRec so that the added record is displayed on the update sub.
Thanks in advance.
Larry De Laruelle
larry1de@yahoo.com
On Click I run some code to concantenate the selections made in a list box and a DLookup to get another needed data item.
I then have a DoCmd.GoToRecord , , acNewRec which errors and tells me that I may be at the end of the recordset.
However, I added another command button to the form to add a record using the same DoCmd.GoToRecord , , acNewRec and rem'ed out the line in the Save event. That works fine.
I've also tried to explicitly save the record prior to the NewRec but that doesn't seem to have any effect.
Any idea what could be causing this? Here is the code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim intLoop As Integer
Dim intRecCnt As Integer
Dim intNumTimes As Integer
'Creates the string for Dosage Times -- stored in DosageTime
intNumTimes = lstTimes.ListCount
For intLoop = 0 To intNumTimes
If lstTimes.Selected(intLoop) = True Then
intRecCnt = intRecCnt + 1
If intRecCnt = 1 Then
DosageTimes = lstTimes.Column(0, intLoop)
Else
DosageTimes = DosageTimes & ", " & lstTimes.Column(0, intLoop)
End If
End If
Next intLoop
'If no times are selected, then a message is displayed to the user requesting a selection.
If intRecCnt = 0 Then
MsgBox "You must select at least one dosage time!", vbOKOnly + vbCritical, "TCC Medical Database"
lstTimes.SetFocus
Exit Sub
End If
'This code identifies the current location of the resident and stores that value in LocationID
LocationID = DLookup("LocationID", "ClientLocation", "ClientID = " _
& Forms!frmMedHistoryInput.cboSelect _
& " AND EndDate Is Null"
DoCmd.GoToRecord , , acNewRec
Forms!frmMedHistoryInput!frmMedHistUpdateSub.Requery
Forms!frmMedHistoryInput!cmdLetter.Enabled = True
frmMedHistoryInput is the main form; frmMedHistUpdateSub is another subform on the main. I want to trigger the requery after the NewRec so that the added record is displayed on the update sub.
Thanks in advance.
Larry De Laruelle
larry1de@yahoo.com