Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I switch form properties with a command button?

Status
Not open for further replies.

PhilWB

Technical User
Sep 15, 2004
21
0
0
AU
I would like to be able to have a form that shows past orders as read only, and have a command button on that form that would allow the entry of new orders.
Is this possible?
I have tried some VBA without success.
Many thanks, Phil
 
Does your form have navigation buttons? Does it acurately show the past records as currently designed? In what mode (eg acFormEdit) was it opened?

If the answers to these are what I expect, you might try this code on the button's click event:

Code:
DoCmd.RunCommand acCmdRecordsGoToNew

Hope this helps!
 
Or....

Me.AllowEdits = True
Me.AllowAdditions = True


Randy
 
I tried the docmd method, that only gives me an error message that the command isn't available now. the allow edits and allow additions sort of worked in that it will open a new form, but it is missing the subform that goes with it.
My code for opening the form from another form is;
Private Sub cmdOrder_Click()
On Error GoTo Err_cmdOrder_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOrder"

DoCmd.Close 'Closes the main form
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly 'Opens the order form
DoCmd.GoToRecord , , acLast 'at the last record, they are ordered on date

Exit_cmdOrder_Click:
Exit Sub

Err_cmdOrder_Click:
MsgBox Err.Description
Resume Exit_cmdOrder_Click

End Sub

The allow edits looks promising, but what am I missing in that the subform isn't available in the newly opened record.
Many thanks, Phil
 
How are ya PhilWB . . . . .
The following applies to both mainform & subform.
Note: [blue]you![/blue] substitute proper names that appear in code in [purple]purple[/purple] . . .
[ol][li]Add a [blue]Checkbox[/blue] to the [blue]underlying table[/blue] (same name for clarity). Set the [blue]default[/blue] property (in the table) to [purple]false[/purple].[/li]
[li]Make sure the checkbox is in the Recordsource of the form, but do not put it on the form.[/li]
[li]In the [blue]AfterUpdate[/blue] event of the [blue]Form[/blue], copy/paste the following:
Code:
[blue]Me![purple][b]CheckboxName[/b][/purple] = True[/blue]
[/li]
[li]In the [blue]OnCurrent[/blue] event of the [blue]form[/blue], copy/paste the following:
Code:
[blue]   If Me![purple][b]CheckboxName[/b][/purple] = True Then
      Me.AllowEdits = False
      Me.AllowDeletions = False
   Else
      Me.AllowEdits = True
      Me.AllowDeletions = True
   End If[/blue]
[/li]
[li]You'll need to set the checkbox for all previously saved records to true. So in a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following:
Code:
[blue]Public Sub UpdateTrue()
   Dim SQL As String
   
   SQL = "UPDATE [purple][b]TableName[/b][/purple] SET [purple][b]CheckboxName[/b][/purple] = True;"
   DoCmd.RunSQL SQL

End Sub[/blue]
[purple]Run the code with proper names per table.[/purple] You can use the [blue]VBE immediate window[/blue] since this is a one time affair.[/li][/ol]
[blue]Thats it . . . give it a whirl & let me know . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan,
That bit of coding wants to work, the only hitch now is that the coding closes the edit option when it enters the sub form, any hints on how to proceed?
Thanks Phil
 
PhilWB . . . . .

In your post origination you said:
PhilWB said:
[blue]I would like to be able to have a form that shows past orders as read only, and have a command button on that form that would allow the entry of new orders.[/blue]
Then laten on you said:
PhilWB said:
[blue] . . . the allow edits and allow additions sort of worked in that it will open a new form, but it is missing the subform that goes with it . . .[/blue]
Currently, the code I provided locks all saved records for form & subform. [blue]You can only edit new records.[/blue]

[purple]What is it you require thats different?[/purple]

Calvin.gif
See Ya! . . . . . .
 
I must have made a blue somewhere in the code, will check that again. It was working as you said, excepting that on a new order, it would cease allowing the edit when the focus moved from the main form to the sub form. This means that order details cannot be entered as planned.
Could the reason be that the tab order is several items from the main form then the subform then back to the main form?
Sorry to be a nuisance.
Thanks Phil
 
PhilWB . . . . .

I simulate this (form with subform linked with master/child porperties) in 2000 & 2002. No problemo . . .
[ol][li]Make sure you have the right code in the right event. Espcially the [blue]BeforeUpdate[/blue] code. If you put the code in the AfterUpdate event of the form, [purple]I get simular to what you've described.[/purple][/li]
[li]Check names & spelling.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
AceMan,
In your original reply you gave me;

In the AfterUpdate event of the Form, copy/paste the following:

CODE
Me!CheckboxName = True
In the OnCurrent event of the form, copy/paste the following:

CODE
If Me!CheckboxName = True Then
Me.AllowEdits = False
Me.AllowDeletions = False
Else
Me.AllowEdits = True
Me.AllowDeletions = True
End If

Do I change the AfterUpdate to a BeforeUpdate?
Thanks, Phil
 
PhilWB . . . . .

Wooooooa . . . sorry about that.

[blue]Yes! move code to the BeforeUpdate event![/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks,
Now it works just like you expected it too :)
Many thanks for all your help.
Phil
 
PhilWB . . . . .

Great! ;-)

You may be more interested in the code I posted here: thread702-98849

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top