Open form to specific record problem

chappy68

Registered User.
Local time
Today, 08:30
Joined
Aug 15, 2011
Messages
76
I have a small problem I am not sure how to correct. I am running the following code from a button in frmSearch. It is all working with a few small quirks. The button does a quick check to make sure only one record is selected. If only one record is selected, it runs the code in red below. When it opens frmTaskDetails instead of having the single record, it has two, the record I want and a new record with no data. I know it is because in the Open event on frmTaskDetails I have the following code: DoCmd.GoToRecord , "", acNewRec. Is it possible to skip this somehow?

Private Sub butIndOpenRecToMod_Click()
'Check to see if NO selections are made. If none, display message box
If DCount("*", "qrySrchAfterSelections") = 0 Then
MsgBox "You must select at least one task to modify. Try again.", vbOKOnly, "Task Selection Error"
Exit Sub
End If
'Check to make sure only one selection is made. If more than one, display message box
If DCount("*", "qrySrchAfterSelections") > 1 Then
MsgBox "You can only select one record to modify. Try again.", vbOKOnly, "Task Selection Error"
Else
'Since only one record is selected, run the code to open frmTaskDetails to the selected record in order to modify

DoCmd.OpenForm "frmTaskDetails", acNormal, "", "[TaskSrch]=" & chkSearch, , acNormal
End If
End Sub
 
The issue is the Form Property

Check your Data Property and select Allow Additions as No

This should prevent the affitional blank row showing which is where you would add a new record.

This is a handy property that can be changed Yes or No as you wish to allow new records or not.
 
Am I able to programatically turn this property on and off? I need this for the bulk of the data entry process for the app.
 
Am I able to programatically turn this property on and off? I need this for the bulk of the data entry process for the app.
You are able to have the Property (plus many others) changed as suits whan the form is opened.
eg, if you open the form and circumstances are such, the Open Event can have the Property set to Yes or No as your code dictates.

The Property must be set to either Yes or No in the form regardless and then the code, if you wish, can change this as required.

If you want assistance with the code, provide some details for your code to consider.
 
Thank you for your assistance. What details do you need? Which form? My search form where I am clicking the button to open the other form or do you need details for the form that is being opened?

I just want to get you the right information.
 
Thank you for your assistance. What details do you need? Which form? My search form where I am clicking the button to open the other form or do you need details for the form that is being opened?

I just want to get you the right information.
If you always don't want to see the additional blank record, then set your form being opened Data Property to Allow Additions = No.

If you want the facility to add new records eg, Open an Invoice. The warehouse should not be able to add a new record. The sales office should have the option.
or Once the delivery has been done, no one is able to add a new record to an invoice.
In this case, provide details of the issue that would effect the Property setting to Allow Additions.
In addition to the Issue (short story) I guess the Name of the form you are on and the form to be opened.
How do you open the 2nd form ? By command button ?

Sometimes, say you have different reasons to open the same form then you may have more then one command button and the code to effect the 2nd form open options could be started with the command button click.
main thing for now is the short story I guess.
 
Here goes. I have a form frmTaskDetails. In the normal process, I open the form and want a new record so there is no data showing. That is why I have the form property for for additions/edits set to yes. In the OnLoad event, I have the following code: DoCmd.GoToRecord , "", acNewRec to create the new record.

Now in my search form frmSearch, once the records are searched, a selection is made via checkbox and then the user clicks a button to view details of the record selected. Once the button is clicked, it opens frmTaskDetails to the record selected. When frmTaskDetails opens, because it fires the OnLoad event, there are now two records in my filtered list instead of one, the selected record and the new record.

I suppose I need to set the Allow Additions property to No before I open the form. Currently, the code for the button to open frmTaskDetails from my search form is:

Private Sub butIndOpenRecToMod_Click()
'Check to see if NO selections are made. If none, display message box
If DCount("*", "qrySrchAfterSelections") = 0 Then
MsgBox "You must select at least one task to modify. Try again.", vbOKOnly, "Task Selection Error"
Exit Sub
End If
'Check to make sure only one selection is made. If more than one, display message box
If DCount("*", "qrySrchAfterSelections") > 1 Then
MsgBox "You can only select one record to modify. Try again.", vbOKOnly, "Task Selection Error"
Else
'Since only one record is selected, run the code to open frmTaskDetails to the selected record in order to modify

DoCmd.OpenForm "frmTaskDetails", acNormal, "", "[TaskSrch]=" & chkSearch, , acNormal
End If
End Sub


Hope this is enough information. Thanks again.
 
When you open the form to view an existing record, use the OpenArgs to send a message to the Open Event of the form. eg
Code:
DoCmd.OpenForm "frmTaskDetails", acNormal, "", "[TaskSrch]=" & chkSearch, , acNormal, "ExistingRecord"

In frmTaskDetails Open Event

Code:
If OpenArgs = "ExistingRecord" Then
Me.AllowAdditions = No
Else
'Do nothing
End If

Try this and see if it works.
 
In frmTaskDetails if I enter your code in the Open event, and set AllowAdditions=No, do I need to, at some point, set AllowAdditions=Yes so that the form operates normally during everyday use?
 
What ever you set the Property to will remain as such.

Open Event will just reset the Property for that instance of form open. Not reset the actual setting you prev had.
 
I guess I shouldn't be so lazy, and just test it. I did and it works just fine.

Thanks you so much.
 

Users who are viewing this thread

Back
Top Bottom