DoCmd not available after outlook code (1 Viewer)

bruceblack

Registered User.
Local time
Today, 13:25
Joined
Jun 30, 2017
Messages
119
Hi everyone! Small problem. Im trying to set a reminder (working!)
But i get error that saving and going to new record is not available now.

Why is it such a problem to run this after my reminder code?
I can't seem to find the problem reading about it. Anyone can explain?

Cheers!!!

Code:
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)
 
With OutlookTask
 .assign
 .Recipients.Add ([EMAIL="test@gmail.com"]test@gmail.com[/EMAIL])
 .Subject = "Registering at desk. Please provide documents."
 .body = "Registering at the expedition desk."
 .startdate = Me.registrationdate
 .ReminderSet = True
 .DueDate = Me.registrationdate
 .ReminderPlaySound = True
 '.ReminderSoundFile = 'Modify path.
 '.Display
 .send
End With
Set OutlookApp = Nothing
Set OutlookTask = Nothing
 
DoCmd.RunCommand acCmdSaveRecord
Me.registeredyesorno.Value = "Yes"
Me.hidesubmitbutton.Value = "Yes"
DoCmd.GoToRecord , , acNewRec
MsgBox "Registration complete!"
 

Micron

AWF VIP
Local time
Today, 08:25
Joined
Oct 20, 2018
Messages
3,478
My advice at this point would be to at least post the beginning of a procedure so we can tell what the event is (assuming there is one). This could be because you're trying to move to a new record in the Open event of a form, which can't be expected to work. I might be wasting your time asking or suggesting something simply because the event isn't identified. If there is a lot of code in between the start and the problem area, sure, remove that if you're sure it's not relevant, but indicate that you have done so, otherwise you'll probably get questions or suggestions on that too.
 

GinaWhipp

AWF VIP
Local time
Today, 08:25
Joined
Jun 21, 2011
Messages
5,899
s this on a Command Button? Is the Form a pop-up? Is the Form filtered when you are doing this?

Also, going to a new record automatically saves the current record so Save not really needed.
 

Micron

AWF VIP
Local time
Today, 08:25
Joined
Oct 20, 2018
Messages
3,478
Also, going to a new record automatically saves the current record
Not if the save fails, right?

As long as we're speculating, I can add more reasons why this error could be raised besides trying to do so in an Open event:
- allow additions is set to No
- allow additions, allow edits, allow deletions all set to No (makes form read only)
- record is snapshot type
- record save was attempted (consciously or not) but failed; warnings may be turned off
- order of events before move attempt prevents the move
- the query underlying the form is not updatable (for one or more of the several reasons why not)
- another user has a lock on the record source


That's about it for now. Time for me to wait for OP to respond.
 

GinaWhipp

AWF VIP
Local time
Today, 08:25
Joined
Jun 21, 2011
Messages
5,899
Not if the save fails, right?

True but you'll get a message which you should trap too either fix the issue or drop the record (not a good idea to drop record obviously).
 

JHB

Have been here a while
Local time
Today, 14:25
Joined
Jun 17, 2012
Messages
7,732
..
But i get error that saving and going to new record is not available now.

Why is it such a problem to run this after my reminder code?
I can't seem to find the problem reading about it. Anyone can explain?
I think the focus is removed away from the form, so the command isn't available.
An example: If you open a report from code, the focus is set on that report, (until you click on something else or move the focus by code).
The solution is to move the focus back to the form before you use the "DoCmd.RunCommand".

Code:
  ..
  Set OutlookApp = Nothing
  Set OutlookTask = Nothing 
  
  [B][COLOR=Red]Me.SetFocus[/COLOR][/B]
  DoCmd.RunCommand acCmdSaveRecord
  ..
 

Users who are viewing this thread

Top Bottom