Controls and visible not visible

Menes

Registered User.
Local time
Today, 14:52
Joined
Sep 21, 2007
Messages
16
Hi all,

I've designed a form in access and want to use it multiple times in Access otherwise I would have to create the same form at least 4/5 times so I would like to do is when the control/button to open the form is used, it applies different controls about what can be done.

For example, the form when used as standard is a data entry form that is used to upload the data to SQL where it is stored. What I then wish to do is use it as read only details form. I.e, once the user is looking at the details for the person, they can not edit the details in any way.

I've been using the example below, I've trimmed it down and am testing it using just one command for the time being. Once I understand how it works, I can then apply it to the other different commands I have.

Code:
Private Sub ID_Click()
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmadd_new_contact"
    
    stLinkCriteria = "[ID]=" & Me![ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Me!Titleaddnewcontact.Visible = False
 
    .AllowAdditions = False
    .AllowDeletions = False
    .AllowEdits = False

    
End Sub

I'm sure I'm applying things in either the wrong order or missing something in the code completely. Any help would be much appreciated as it would save me creating the form many times.

Thanks.
 
What's the question? For starters, the 3 lines relating to editing the form appear to have been taken out of a With block. They would error as is.
 
What I'm hoping to do is as follows just using one example:

Button 1 - The form opens and data can be entered.
Button 2 - The form opens and no edits can be made.

Ignoring the visible part for the moment, this is the most important thing that I want to get right is how to lock/unlock the form based on a command button.

The only other method I found when I was searching was to use something like

Forms!frm_add_new_contact.RecordsetType = conSnapshot

But I don't if thats right either. I'm really not an expert as I'm sure you've guessed but if I can understand it once I can then apply it elsewhere.

Thanks
 
I understand what you're trying to do. When you post code, tell us what's happening. Does it error? If so, what's the error? Does it not do what you expect? Like I said, the lines starting with a period are going to error. You want:

Forms!frmadd_new_contact.AllowAdditions = False
 
Paul,

My apologies, I mis-understood what you meant.

Thanks for the code. I've put it in now and it does do something. When I click on it to bring up the form it just brings up a blank form. By this I mean just a grey coloured square with nothing on it all.

I'm not sure why this is. Is it because the link is not working correctly? I.e. the ID connection between the two is incorrect or is something more basic that I also need to set as well as the allow statements?

Thanks
 
You can get a blank form if there's no data in the record source and the form doesn't allow additions. That implies maybe the link isn't working correctly. If you open it setting the AllowAdditions property to True does it show the textboxes? Can you post the db here?
 

Users who are viewing this thread

Back
Top Bottom