[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

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

err

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!
0
SeyerIT
Asked:
SeyerIT
  • 3
  • 3
1 Solution
 
hnasrCommented:
You can do that. Assume Form01, Form02 with record source: a(f1, f2)
Assume Form1 with command button:

Private Sub Command1_Click()
    DoCmd.OpenForm "Form02", acNormal, , , , acHidden ' you can run this from a different command button
    Form_Form02.PublicRecordMoveNext
End Sub

Open in new window


Form2 class code:

Option Compare Database

Public Sub PublicRecordMoveNext()              ' it has to be public
    DoCmd.GoToRecord acDataForm, "Form02", acNext
    Debug.Print f1, f2
End Sub

Open in new window

0
 
SeyerITAuthor Commented:
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;
crash
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"
0
 
SeyerITAuthor Commented:
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!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
hnasrCommented:
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.
0
 
SeyerITAuthor Commented:
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!
0
 
hnasrCommented:
Welcome!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now