open a form based on the record that is selected in current form (1 Viewer)

s_samira_21

Registered User.
Local time
Today, 18:52
Joined
Jun 8, 2011
Messages
52
Hi again

I have a split form named Organization_List that has a field named Details an one other field named ID.
Also I have a form named Organization_Details, too.
I want that when the user click on the details field of a record Organization_Details form opens, so that contains the details of that specific record.
I used the macro in access samples but it does not work. Also I prefer to use VBA code.
Anybody to help me?
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
OpenArgs is usually a bit too complicated for that. Just adding a where clause to the OpenForm command is enough:
Code:
Private Sub cmdOpenDetail_Click()
[INDENT]DoCmd.OpenForm "frmDetail", , , "recordID = " & Me!recordID
[/INDENT]End Sub

Will suffise in most cases
 

s_samira_21

Registered User.
Local time
Today, 18:52
Joined
Jun 8, 2011
Messages
52
thank you very much
but unfortunately it doesn't work
I wrote the code but the Organization_Details form opens in a blank record
but something that is funny, is that this code works just for one of the records, that its ID is 14!!!!!


than I used OpenArg, too. but here for each record the form opens only with 14th record's details!!!!!!!!
 
Last edited:

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
Please post your code here.

I'm guessing either you didn't change the where clause, "recordID = " & Me!recordID
, to the appropriate primary key field for your form ("orgID = " & Me!orgID perhaps)?

Also bear in mind that if the primary key field is a string then it will need to be surrounded in quotes:
"orgID = " & Chr(34) & Me!orgID & Chr(34)

If not that then check Organisation_Details is not set to Data Entry and does Allow Filters.
 
Last edited:

s_samira_21

Registered User.
Local time
Today, 18:52
Joined
Jun 8, 2011
Messages
52
Private Sub cmd_Details_Click()
DoCmd.OpenForm "Organization_Details", , , "ORGANIZATION_ID_ = " & Me!ORGANIZATION_ID_​
End Sub
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
Open the Organization_Details form in design view and check the Properties of the form > Data Tab > Data Entry (needs to be No) and Allow Filters (needs to be Yes) properties.

Having a field end in an underscore is strange. Is that a typo?
And like I said, can we just confirm it is a number field not a text field. (if it's text you'd need to put quotes round it:
DoCmd.OpenForm "Organization_Details", , , "ORGANIZATION_ID_ = " & Chr(34) & Me!ORGANIZATION_ID_ & Chr(34)
)

Also, just check that ORGANIZATION_ID_ is the primary key and is included in the record source of both forms.
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
than I used OpenArg, too. but here for each record the form opens only with 14th record's details!!!!!!!!

Don't use both.
OpenArgs will be more complicated (you'd have to check for the OpenArgs and filter according to it in code in the Organization_Details on Load event)


It sounds like there might be a filter there already.
Check the Server Filter property of the Organization_Details form is empty (and delete it if it isn't)

One very annoying 'feature' of Access is if a form bugs out while a filter is applied to it and you fix the bug and save it and click 'play' it applies whatever filter there was as a Server Filter on the form (the form will always have that filter). You have to watch out for that.
 

s_samira_21

Registered User.
Local time
Today, 18:52
Joined
Jun 8, 2011
Messages
52
i dont use both of the ways together....

there is no filter!!!
I don't know whats the problem
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
Private Sub cmd_Details_Click()
DoCmd.OpenForm "Organization_Details", , , "ORGANIZATION_ID_ = " & Me!ORGANIZATION_ID_
End Sub

Are you sure the field is called ORGANIZATION_ID_?

In the original post you said the field is called ID

If so then the line would be

DoCmd.OpenForm "Organization_Details", , , "ID = " & Me!ID

As to why it's always opening Organisation_Details at the 14th record:
Does it do that when you open the form 'manually'?
It can only be for these possible reasons:
  1. The '14th' record is actually the first record in the table
  2. There is a filter either in the form's properties or in the form's record source
  3. There is some code in the Forms Load or Current event that's telling it to either filter itself or goto that record.
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
I've made a demo database of how this system should work.

You can compare yours to it.

There are two versions of the Open Detail button.
The sophisticated one tries to save the record if it's new and opens the detail as a dialogue and then requeries the list to show any changes made in the detail.
 

Attachments

  • OpenDetailFromListDemo.accdb
    544 KB · Views: 1,503

s_samira_21

Registered User.
Local time
Today, 18:52
Joined
Jun 8, 2011
Messages
52
no no no :((
no filter
no extra code
14th is not the first record


when i click on details of each record an empty Organization_details form opens. but when i click on details of the record that its Id is 14, form opens with correct details!!!

the code only works for that record!!!

:((
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
Are the other record ID's equivalent (e.g.1,2,3,5,9 etc)?

Perhaps you could create a blank database, import the table and the two forms and post that here so I can have a look.

As per the demo I posted it should be simple and completely reliable to do.

There must be something strange going on.
 

s_samira_21

Registered User.
Local time
Today, 18:52
Joined
Jun 8, 2011
Messages
52
the data that I entered is in Persian. I don't know if you can understand it or not...
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
The data could be in martian, it shouldn't make any difference unless there's non-roman letters or non-arabic numerals in the ID field, which there shouldn't be
 

VilaRestal

';drop database master;--
Local time
Today, 15:22
Joined
Jun 8, 2011
Messages
1,046
OK I'm downloading it now.
I should say if there's anybody's personal information in the database then you should edit your post and remove the link. (To be honest databases with that sort of information shouldn't be uploaded, we should work on copies with demo data)
 

Users who are viewing this thread

Top Bottom