cres1121
asked on
Saving data on a subform when I close the form
I have a subform that I got by filtering from a form thru vba and a double click. I pass thru a field called linenumberid. So my users double click and I give them information that is stored in another table based on that line ID. If there is no information it comes up blank.
I would like the users to be able to edit the information or in some cases add it. I would like it to store all the information or update it as the case may be when they close the form. It can be with a message that your changing the information are you sure.
I know you have to do it on exit but how do I get the linenumberid to fill in when there is no record already in the table?
Can someone help me with the vba?
I would like the users to be able to edit the information or in some cases add it. I would like it to store all the information or update it as the case may be when they close the form. It can be with a message that your changing the information are you sure.
I know you have to do it on exit but how do I get the linenumberid to fill in when there is no record already in the table?
Can someone help me with the vba?
ASKER
You are correct this is a popup but not from the master and child. It is from the child to another table. We have another table that stores information about the child. Thru the experts help there is a check box that shows there is data in the table. We then double click on the line number which pops up the information.
I, of course, was not satisfied with just viewing it. I now want to add information if the record is blank and change it in some cases.
So it does not pass the line number if the record did not exist in the first place. I can't do a subform because it is not related to the master record but to the child record.
I hope I am making sense.
I, of course, was not satisfied with just viewing it. I now want to add information if the record is blank and change it in some cases.
So it does not pass the line number if the record did not exist in the first place. I can't do a subform because it is not related to the master record but to the child record.
I hope I am making sense.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am so thick on this so I have a event procedure on a double click on the subform that calls to the popup
Private Sub line_item_number_DblClick( Cancel As Integer)
DoCmd.OpenForm "TBLservicelinedetails", WhereCondition:=" [line item number] = " & Me.[line item number]
End Sub
Line number is the PK on the subform and FK on the Popup... Where do I add in the code you are referring too.
The tblservicelineitem subform is housed in the master form.
Private Sub line_item_number_DblClick(
DoCmd.OpenForm "TBLservicelinedetails", WhereCondition:=" [line item number] = " & Me.[line item number]
End Sub
Line number is the PK on the subform and FK on the Popup... Where do I add in the code you are referring too.
The tblservicelineitem subform is housed in the master form.
You probably have to add:
, OpenArgs:= & Me.[Line item number] '''''to the end of the existing statement.
I don't use this particular syntax so I can't help you with it.
, OpenArgs:= & Me.[Line item number] '''''to the end of the existing statement.
I don't use this particular syntax so I can't help you with it.
ASKER
I wish I had your head and I am sorry I am slow... But .. of course I got a error...
I know it is not your syntax but I am getting
Runtime error '3075'
Syntax error (comma) in query expression '[Line item number],openargs:=12665'.
Private Sub line_item_number_DblClick( Cancel As Integer)
DoCmd.OpenForm "TBLservicelinedetails", WhereCondition:=" [line item number],openargs: = " & Me.[line item number]
End Sub
I know it is not your syntax but I am getting
Runtime error '3075'
Syntax error (comma) in query expression '[Line item number],openargs:=12665'.
Private Sub line_item_number_DblClick(
DoCmd.OpenForm "TBLservicelinedetails", WhereCondition:=" [line item number],openargs: = " & Me.[line item number]
End Sub
Using this syntax, you will get intellisense as you type:
docmd.OpenForm "TBLservicelinedetails",ac Normal,," [line item number] = " & Me.[line item number],,,Me.[line item number]
The last argument is the OpenArgs. There is nothing wrong with the syntax you are using and in fact it is clearer. I am just not familiar with it so I don't know the names of the arguments so it is hard to modify the code.
docmd.OpenForm "TBLservicelinedetails",ac
The last argument is the OpenArgs. There is nothing wrong with the syntax you are using and in fact it is clearer. I am just not familiar with it so I don't know the names of the arguments so it is hard to modify the code.
ASKER
Okay that worked great and I know I am probably asking too many questions.
It worked if we have detaisl in the tblservicelinedetails.
But if linenumber 12665.does not have detail it does not fill in the line number I just clicked on. I want to be able to pass that line number to a blank record so I can add it to the table. I would have to find the right line number to do it correctly now.
I did add the before insert on the popup
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.FKfield = Me.OpenArgs
End Sub
It worked if we have detaisl in the tblservicelinedetails.
But if linenumber 12665.does not have detail it does not fill in the line number I just clicked on. I want to be able to pass that line number to a blank record so I can add it to the table. I would have to find the right line number to do it correctly now.
I did add the before insert on the popup
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.FKfield = Me.OpenArgs
End Sub
Did you place the "fill" code in the popup form's BeforeInsert event?
Me.detaisl = Me.OpenArgs ''' assuming the FK name is the same as the PK name
Me.detaisl = Me.OpenArgs ''' assuming the FK name is the same as the PK name
ASKER
Got it... Thank you! Thank you for helping and thank you for your patience!
ASKER
This turned out to be more than one simple question but so helpful! Thank you!
You're welcome.
It sounds like you actually have a popup form rather than a subform. A subform is embedded in another form and by setting the master/child links, Access will keep the two in sync and will automatically fill the subform's FK when a new record is entered. A popup form is a main form and so you would have to populate the FK yourself. The best event to use is the popup form's BeforeInsert event. This event fires immediately as soon as the first character is typed into any new record and it doesn't fire for existing records. You can either pass in the FK value using the OpenArgs or you can have the popup form reference the form that opened it.
Me.SomeFK = Forms!callingform!PK