Link to home
Start Free TrialLog in
Avatar of Jeremy Campbell
Jeremy CampbellFlag for United States of America

asked on

Trying to run commands on hidden form from another form using vba

Here is what I'm trying but I'm getting the following error at the .DoCmd.GotoRecord,,acNewRec Line

User generated image

Here is my code;

DoCmd.OpenForm "frmSendNotify", , , , , acHidden
With [Forms]![frmSendNotify]
    .DoCmd.GoToRecord , , acNewRec
    .NotifyText = fOSUserName() & " - " & Me.Desc
    .docmd.Close
End With


Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jeremy Campbell

ASKER

Sorry I'm just getting back to you on this and thanks for the response!

The code appears to work but for some reason when I try the code running my program outside of programming mode access completely crashes when I try to execute it.

Here is a screenshot;
User generated image
When I run the code in programming mode from access everything runs perfectly.. Going to just try and debug it by eliminating the few extra lines I added in. Here is my code for it;

Me.GenFrom = Me.txtForm
Me.DateSubmitted = Now()
Me.SubmittedBy = fOSUserName()

DoCmd.OpenForm "frmSendNotify", acNormal
    Form_frmSendNotify.PublicRecordMoveNext
    Form_frmSendNotify.UserName = "jmeyer"
    Form_frmSendNotify.NotifyText = "New Request from " & fOSUserName() & ": " & Form_frmEnhancements.Desc
    Form_frmSendNotify.DateSent = Now()
 
DoCmd.Close acForm, "frmSendNotify"
DoCmd.Close acForm, "frmEnhancements"
Ok.. figured out what was causing it to crash although I don't know why.

The line:
Form_frmSendNotify.PublicRecordMoveNext
that fired the code;
Public Sub PublicRecordMoveNext()              ' it has to be public
    DoCmd.GoToRecord acDataForm, "frmSendNotify", acNext
    Debug.Print f1, f2
End Sub

for some reason caused it to crash when it was running from the user interface.

I removed that portion of it and added an On Open event to the frmNotify;

Private Sub Form_Open(Cancel As Integer)

    DoCmd.GoToRecord , , acNewRec

End Sub


I really don't know why that was causing the entire program to crash and why it didn't in programming mode but adding the OnOpen code fixed it.

Thanks for the help!
Welcome!

"I really don't know why that was causing the entire program to crash and why it didn't in programming mode but adding the OnOpen code fixed it."

No use of discussing this here, I dont' have an immediate explanation for such issue. You may open a new question exploring that statement. A required solution is not fixing but explaining why.

You need to upload a sample database recreating the problem.
Yeh, I'm just going to leave that one alone.. It's working and that's all I'm concerned about now.. I'll post something else on it if it comes up again and I'm unable to remedy it. :)

Thanks again for your help!
Welcome!