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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update/Save A Main Form Record from a Subform

Status
Not open for further replies.

sonseph14

Programmer
Mar 23, 2006
16
0
0
US
We have created a form with a subform in our database. The subform is related to the mainform via a TransactionID. The subform is a continuous form used to enter products being bought by a customer. When we first enter the form we have focus set to the first field in the subform because this is where the information is going to be entered. The problem that occurs is that when we get to the end of the record in the subform and tab out, it won't let us save the record because it needs a record to be saved in the main form which it is linked to. The only way we can get this to work is if we click in a field in the main form then return to the subform to enter the product. By doing this, the main form record is saved to its table and thus the subform record will then save. Is there anyway to get around this?? Any help would be appreciated.
 
I can suggest this. not very elegant but effective. You could create a button in the main form which performs the required action. You can assign the button with a label like "E&Xecute" (or whatever you want). This kind of label means that if you press ALT + X you activate the button.
in order to "automatically" press the button from a piece of VB code you just need this line
SendKeys "%X"

hope it can help you

Alex
 
When you create the button, I'm assuming the label goes into the name field. If this is correct, do I put the name in quotes as you have listed or is it just the text? I've attempted to use the code, but haven't had luck with it.
 
you don't use the quotes it is just the text you see in the button when you activate/use the form. The goal is to have a button with an Underlined letter (the X in my example). try it out
 
Alternatively, if you have a bound control on the main form that can be filled automatically, a date field for example, before you go to the subform, the record will be created.
Code:
Private Sub Form_Current()
Me.txtTextBox = Date
DoCmd.GoToControl "tblOrderLine subform"
Me.tblOrderLine_subform.Form.txtTextBox.SetFocus
End Sub

ps DoCmd.RunCommand acCmdSaveRecord

 
The button solution worked. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top