To open form with a specified record (1 Viewer)

JRPMD

Registered User.
Local time
Today, 05:39
Joined
Nov 24, 2012
Messages
52
Hello , I have a form , Form1 , in wich I can see the second record of a query.
I wrote this code : DoCmd.GoToRecord , , acGoTo, 2 at the OnOpen event and it works properly showing the second record of the query with an Autonumber field.
Now I made a new form , Form2 , from a different table , and Form1 as a subform ,
with this code : DoCmd.GoToRecord ,"Form1" , acGoTo, 2 .
But it doesn't works.
I get this message : Error 2489 , the object "Form2" is not open.
How can do this ?
Thank you very much!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:39
Joined
Oct 29, 2018
Messages
21,536
Hi. The Open event of a subform fires before the Open event of the main form. Maybe that’s what the error means.
 

JRPMD

Registered User.
Local time
Today, 05:39
Joined
Nov 24, 2012
Messages
52
Thank you very much!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:39
Joined
Oct 29, 2018
Messages
21,536
Thank you very much!
Hi. You're welcome. If you tell us what you're trying to accomplish, perhaps we can guide you on how to do it.
 

JRPMD

Registered User.
Local time
Today, 05:39
Joined
Nov 24, 2012
Messages
52
Alright , I have to print a daily report in A4 sheet and have very little space because of many reports and subreports in that sheet .
Now I have a form ( or report) with fields like , Name , Id , date of birth , gender , Admission diagnosis, etc. And then another table and form with a field Evolution diagnosis , in wich there are between one and three records a day , all in the same column , as a subreport.
I can save space putting in the same row (and not in a column) three subreports each one with on record , the first , the second and the third , so that is why I need a query or a code that returns that specified record.
Thanks in advance!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:39
Joined
Oct 29, 2018
Messages
21,536
Hi. You’re sort of mixing things with forms and reports and subforms and subreports. If you need a report, just create one from your table or query, not from a form. How are the records between the tables related? If they are, you should be able to create a query for your report. If they’re not related, you could probably use the DLookup() function to look up the records from the tables. If you can post a sample copy of your db with test data, we can show you how to do it.
 
Last edited:

JRPMD

Registered User.
Local time
Today, 05:39
Joined
Nov 24, 2012
Messages
52
Hi, theDBguy , sorry I was trying to reduce my DB (50M) and creat a new DB with a few tables , forms and reports related to the question I made.
Now the code seems to work properly and retrieve the first , second and third records of a table (altough sometimes there is an error).
The code in forms "Diagnostico evolutivo...." is:
Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acGoTo, 1
End Sub
Thank you very much.
 

Attachments

  • UCI5 copia1.accdb
    1.7 MB · Views: 109

mike60smart

Registered User.
Local time
Today, 13:39
Joined
Aug 6, 2017
Messages
1,915
Hi

There is something wrong with this database.

You have a total of 17 Tables and none of them is related by using a Primary / and Foreign Key??

How have you managed to enter data in supposedly related tables?

What is the purpose of the database??
 
Last edited:

JRPMD

Registered User.
Local time
Today, 05:39
Joined
Nov 24, 2012
Messages
52
Hello theDBguy , the tables are related in the original DB by the field [Nro de Orden].
I made a reduced version , with only a few objects ,wich is under 2MB in order to post it.
My main interest was the code :
"Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acGoTo, 1
End Sub".
Now suprisingly it's working well , and it can show the specified record ( first, second and third) , as you can see in the three subforms called Diagnosticos evolutivos.
My be this simplified DB allows the code work properly and I have to redesign the original one.
I take your advice and will make subreports instead of subforms.
I think this matter is solved .
Thank you very much for your interest!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:39
Joined
Oct 29, 2018
Messages
21,536
Hello theDBguy , the tables are related in the original DB by the field [Nro de Orden].
I made a reduced version , with only a few objects ,wich is under 2MB in order to post it.
My main interest was the code :
"Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acGoTo, 1
End Sub".
Now suprisingly it's working well , and it can show the specified record ( first, second and third) , as you can see in the three subforms called Diagnosticos evolutivos.
My be this simplified DB allows the code work properly and I have to redesign the original one.
I take your advice and will make subreports instead of subforms.
I think this matter is solved .
Thank you very much for your interest!
Hi. Congratulations! Good luck with your project.
 

Users who are viewing this thread

Top Bottom