Solved DoCmd.OpenForm Does Nothing (1 Viewer)

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
I am at a loss. I am a very basic user of Access and probably don't use it the way most would. I have created several databases for various plant things I do (Dahlia tracker, Seed Stash, etc). I have just created a new database for 'Seed Starting Journal' where I want to keep records on seeds I start.

The form name is 'Seed Starting Journal.' I have a report I've created for 'Seeds Not Germinated.' This is where I am at a loss. I am using the below code (via Build Event). The goal is to click an item in the report and have it take me to that record in the form, in case I would like to update the record or edit it (hence the acFormEdit).

Private Sub Plant_Name_Click()
DoCmd.OpenForm "Seed Starting Journal", acNormal, , "id = " & Me.ID, acFormEdit
End Sub

The reason I am at a loss is I have used this exact code (after much googling and digging when I first figured out how to make it work) in my other databases I have set up. But for some reason, it does absolutely nothing in this new Seed Starting Journal database. No error code. I have spelled the form name correctly. The ID record is on the form (not visible, but it's not visible in any other databases where it works). It is the automatically generated numerical ID number for each entry in the form. I have even tried doing just this code:

Private Sub Plant_Name_Click()
DoCmd.OpenForm "Seed Starting Journal"
End Sub

Nothing. I go to my Report View and click on a plant name, and nothing. No error. It doesn't open the form at all. It's as if there is no coding. Can someone please help? I have even went in and did a "Compact & Repair" on the database. What am I missing?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:28
Joined
Feb 19, 2013
Messages
16,616
If you put a stop on the code - does it stop on the docmd line?

I’m thinking your report does not have [event procedure] against the plant name click event
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:28
Joined
Feb 28, 2001
Messages
27,188
Just as a sanity check, does the form open when launched manually from the navigation panel's list of reports?

CJ is probably right, but the sanity check never hurts.
 

XPS35

Active member
Local time
Today, 23:28
Joined
Jul 19, 2022
Messages
159
I am confused.
Seems like you try to open a form from a report? That's not what reports are for. Reports are for printing data. A usual way of operating is that you have a form with a button to open/print a report. If you want you can select a record on the form to only print that record.
 

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
If you put a stop on the code - does it stop on the docmd line?

I’m thinking your report does not have [event procedure] against the plant name click event
I'm not sure what you mean by 'put a stop on the code.'

I checked, and there is an [event procedure] tied to the plant name click event, unless you are referring to something else.

event.jpg
event2.jpg
 

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
Just as a sanity check, does the form open when launched manually from the navigation panel's list of reports?

CJ is probably right, but the sanity check never hurts.

Yes, the form opens properly when I click on it from the navigation panel.
 

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
I am confused.
Seems like you try to open a form from a report? That's not what reports are for. Reports are for printing data. A usual way of operating is that you have a form with a button to open/print a report.

I realize I am probably not using it the way most people would, but this way works for what I need, if I can get the code to work properly. I haven't had an issue with using it this way in other databases I've created.
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:28
Joined
Jan 23, 2006
Messages
15,379
Interesting. Normally, as has been said, you do your selecting in a form, and then display the selected info as a result in a report.
However, I just tested a report of my own where there is a control called Name on the report
I added some code to create a click event on the name control.
Code:
Private Sub name_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
        Debug.Print ctl.name, ctl.ControlType
    Next
    DoCmd.OpenForm "frmCheckFiles"

This event procedure lists the report's control names and types to the immediate window, then opens a completely independent form ---successfully.

I wonder in your case if Me.Id is an issue??
 

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
Interesting. Normally, as has been said, you do your selecting in a form, and then display the selected info as a result in a report.
However, I just tested a report of my own where there is a control called Name on the report
I added some code to create a click event on the name control.
Code:
Private Sub name_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
        Debug.Print ctl.name, ctl.ControlType
    Next
    DoCmd.OpenForm "frmCheckFiles"

This event procedure lists the report's control names and types to the immediate window, then opens a completely independent form ---successfully.

I wonder in your case if Me.Id is an issue??

I'm afraid you lost me on the above a little. I included a screenshot of what I entered in the Event Procedure box but it did nothing. However, I'm sure I did it wrong.

controls.jpg

I have used the Me.Id in other reports on other databases without an issue. 😞 That's always been the way to uniquely identify which form entry I would like to pull up for more info.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:28
Joined
Sep 21, 2011
Messages
14,310
See my link on debugging in my signature. No time like the present to start learning if you want tokeep using access.
The code looks fine to me (I always have to check the syntax.
Put a breakpoint on that Docmdline and then run the report.
That should take you into that section of code. If it does not, then that is your problem.

Failing that, compact, zip and upload you db as a last resort.
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:28
Joined
Jan 23, 2006
Messages
15,379
I was not intending to confuse you. I ran a test to confirm the activity of a click event on a report control. And the test was successful. Did what was expected.
So the click event on the report control should work. Possibly some of the parameters on the DoCmd.OpenForm were an issue.

Did your test in #9 print anything in the immediate window?
 

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
Okay, maybe this info will help narrow down the issue. I have since created 2 more simple databases to test to see if this will work. The first one, this code worked and did exactly as I was hoping it would do in a report.

Code:
Private Sub Plant_Name_Click()

DoCmd.OpenForm "Seed Starting Journal", acNormal, , "id = " & Me.ID, acFormEdit

End Sub

I closed out the file and came back to it later, and now it doesn't work. The event procedure is still there, but, as is with my database that isn't working, when I click the plant name, nothing happens at all. No error message, and it does not open that form record anymore. But it worked before closing the file, and I have added nothing new to that test database since then.

I tested this with another database this morning, this time doing an OnLoad for the form itself, and not a report. I used the following code as it works great in other databases I've created, taking me to the last record in the form.

Code:
Private Sub Form_Load()

DoCmd.RunCommand acCmdRecordsGoToLast

End Sub

That code worked after closing out of the form (not Access) and reopening the form. It took me to the last record. I closed access, reopened it, and when I clicked on the form in navigation, it was at the first record. It's as if all event procedures just stop working after I close access for the first time. 😞
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:28
Joined
May 7, 2009
Messages
19,245
can you use Timer Event?

Code:
Private Sub Form_Load()

Me.TimerInterval = 60

End Sub

Private Sub Form_Timer()
Me.TimerInterval = 0
Docmd.GoToRecord ,,acLast
End Sub
 

Minty

AWF VIP
Local time
Today, 22:28
Joined
Jul 26, 2013
Messages
10,371
Check you haven't got a Windows or Office update in an incomplete state of updating.
I would also consider doing an Office repair.

You haven't recently installed a new virus checker or similar by any chance?
It definitely sounds as if something external to Access is causing an issue. Can you upload one of the sample databases you created that has the problem? (You'll need to reach 10 posts before you can attach anything BTW)
 

april522

New member
Local time
Today, 16:28
Joined
Feb 6, 2023
Messages
7
Well, I finally figured out the issue, stumbling upon it by pure accidentally. I'll post what the problem was for me in case anyone in the future has an issue with this. I clicked on File --> Info and was going to compare database settings with the one not working to one that was working. And there it was! So much time spent trying searching to figure out why this simple code wouldn't work all of a sudden...

Security Warning.jpg

After I clicked to enable all content, everything worked like a champ again. When I did the Compact and Repair earlier, I just typed it into the 'tell me what you want to do box' and never went to this screen to do it. Had I went here first (I couldn't remember where it was located because it had been a while), I would have seen the issue sooner. 😂
 

Kamayo Ako

Member
Local time
Tomorrow, 00:28
Joined
May 23, 2022
Messages
89
Well, I finally figured out the issue, stumbling upon it by pure accidentally. I'll post what the problem was for me in case anyone in the future has an issue with this. I clicked on File --> Info and was going to compare database settings with the one not working to one that was working. And there it was! So much time spent trying searching to figure out why this simple code wouldn't work all of a sudden...

View attachment 106289

After I clicked to enable all content, everything worked like a champ again. When I did the Compact and Repair earlier, I just typed it into the 'tell me what you want to do box' and never went to this screen to do it. Had I went here first (I couldn't remember where it was located because it had been a while), I would have seen the issue sooner. 😂
To avoid that issue please refer to attachment.
 

Attachments

  • System Settings Guide.pdf
    1.9 MB · Views: 82

Users who are viewing this thread

Top Bottom