Open a form in a specific record but in different state

aian

Registered User.
Local time
Today, 22:56
Joined
Jan 28, 2005
Messages
70
Hi to all!

I have a form "Products". I want to add two buttons, one named "See photos" and one named "Assign photos". Both of them will open the same form "Photos", but the first will open the form in a state that will not allow the user to change anything, while the second will allow the user to add or edit the photos assigned to the Product.

The problems I have are:

1. How do I force the "Photos" form to open in "view only" mode when I click the "See photos" button?
2. How do I force the "Photos" form to open in "edit" mode when I click the "Asign photos" button, so that the "Photos" form will have the Product ID pre-entered and not be required to be added by the user?

Note that the "Photos" form is bound to a table named "Photos", that has an field named ProductID which is what connects this table with the Products table.

Hope I explained everything...

Thank you in advance
 
Last edited:
When you click on the button use the DoCmd. to set the edit mode

DoCmd.OpenForm "Fred", acNormal, , , acFormReadOnly

or

DoCmd.OpenForm "Fred", acNormal, , , acFormEdit
 
I would suggest passing the form a value in the openargs feature and when the form opens you run code that sets it up in a specific state depending on the openarg value. I can whip a sample db if you need one...
 
Search OpenForm method in access help, you are looking for Docmd OpenForm syntax.

JR
 
Thank you all for your answers, but I'm afraid my knowledge level isn't anywhere that high...

Could you please be a bit more specific?
And please use the names of the forms, buttons and tables I used before so as to help me understand what I click on what.

Thank you all again.
 
Thank you all for your answers, but I'm afraid my knowledge level isn't anywhere that high...

Could you please be a bit more specific?
And please use the names of the forms, buttons and tables I used before so as to help me understand what I click on what.

Thank you all again.

DCrake gave you all of the information that you will need. All you need to do is substitute the name of your Form when he has the word FRED
 
Aha! So that's what "Fred" meant...

Thank you!
 
But where do I type the text DCrake wrote?
Is it at the button's OnClick property?
 
Thank you Bob and DCrake. That worked great.

The problem I'm facing now is that when I click the "Assign Photos" button (DoCmd.OpenForm "Photos", acNormal, , , acFormEdit), the form "Photos" doesn't open with the ProductID preselected so that the user may just assign the photos. Instead, it opens showing the first ProductID (meaning the first record) and the photos assigned to it. How do I solve this?
 
Thank you Bob and DCrake. That worked great.

The problem I'm facing now is that when I click the "Assign Photos" button (DoCmd.OpenForm "Photos", acNormal, , , acFormEdit), the form "Photos" doesn't open with the ProductID preselected so that the user may just assign the photos. Instead, it opens showing the first ProductID (meaning the first record) and the photos assigned to it. How do I solve this?

You can add a criteria clause to the OpenForm Statement.

DoCmd.OpenForm "Photos", acNormal, , "ProductID = [ProductIDFieldonYourForm]", acFormEdit
 
MSAccessRookie, thank you.

When I do what you suggested and I click on the "Assign Photos" button, the form doesn't open. Instead Access asks for the parameter ProductID.

Maybe I didn't write it correctly.

I want the form to have the ProductID pre-entered, even though the form "Photos" and its underlying table "Photos" have no previous record with the same ProductID. It's as if the user would open the form "Photos" and have the ProductID automatically taken from the "Products" form, instead of typing it by himself.

Can this be done?

If not, then could you suggest another way?
Maybe when the user adds a new record in the "Products" table through the "Products" form, to have an automated way of adding a new record to the table "Photos" with just the "ProductID", so that when the user clicks on the "Assign Photos" button, the form "Photos" will already have the ProductID and not ask for it.

Thank you all for your time and effort.
 
MSAccessRookie, thank you.

When I do what you suggested and I click on the "Assign Photos" button, the form doesn't open. Instead Access asks for the parameter ProductID.

Maybe I didn't write it correctly.

I want the form to have the ProductID pre-entered, even though the form "Photos" and its underlying table "Photos" have no previous record with the same ProductID. It's as if the user would open the form "Photos" and have the ProductID automatically taken from the "Products" form, instead of typing it by himself.

Can this be done?

If not, then could you suggest another way?
Maybe when the user adds a new record in the "Products" table through the "Products" form, to have an automated way of adding a new record to the table "Photos" with just the "ProductID", so that when the user clicks on the "Assign Photos" button, the form "Photos" will already have the ProductID and not ask for it.

Thank you all for your time and effort.

Two suggestions:
  1. Is the actual name of the Column Name ProductID (not [Product ID], Product_ID or something else)? I only game an example of what could work. If I did not use a correct name, please make any appropriate chagnes and try again.
  2. Sometimes, references to Controls and Columns seem to require the presence of brackets ("[", "]"). Try adding them.
 
I have included everything correctly and adjusted the names accordingly. I didn't need to add the brackets because they were already present.

I think the problem has to do with the fact that the button "Assign Photos" opens the form "Photos", but the form (well, the table "Photos" behind the form) doesn't have beforehand a record with the relevant ProductID. That's why Access is poping up the window asking me for it.

Any ideas?
 
I have included everything correctly and adjusted the names accordingly. I didn't need to add the brackets because they were already present.

I think the problem has to do with the fact that the button "Assign Photos" opens the form "Photos", but the form (well, the table "Photos" behind the form) doesn't have beforehand a record with the relevant ProductID. That's why Access is poping up the window asking me for it.

Any ideas?

Can you provide a screen shot of the message prompt?
 
Sure!

Here it is (even though in Greek, you'll get the idea)
 

Attachments

  • sshot.jpg
    sshot.jpg
    38.6 KB · Views: 133
Looks like you have something in brackets spelled wrong.
 
Ken, you were right.

But the form still opens without the ProductID pre-written...
 
I go back to the openargs thing because it gives you more control and the filter param thing is hard to figure out at times.
 
I didn't quite understand how to use the openargs thing, can you explain please?
 

Users who are viewing this thread

Back
Top Bottom