• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Add Value to Subform If Not Null

I have a main form that contains 3 subforms.  The subforms capture Material Usage data for the associated machine and the data is stored in tbl_MaterialUsage.

tbl_MaterialUsage
=============
MaterialUsageID (PK)
ProdID (FK - Parent Field to subforms)
Material ID
MaterialUsage (Amount)
Machine ID

The attached screenshot shows the subforms...Each line is a subform that corresponds to a specific machine.  I need a way of storing that machine ID, but I do not want to store records unless the user enters information in the Material and Usage fields on that subform.  ProdID, MaterialUsageID, and MachineID are hidden in the subform.

Also, if you have any other methods or design suggestions, I would love to hear them as I suspect my use of multiple subforms may not be the most effective.
FormSample.bmp
0
alliedtech
Asked:
alliedtech
  • 4
  • 3
1 Solution
 
wiswalldCommented:
I am a little confused. You want to add a machine ID to the subform but if they do not fill in the other fields to not save the record?
0
 
alliedtechAuthor Commented:
My overall goal is to avoid saving records that do not have a Material or a Usage.  If I set the Machine ID to a default value, then I believe the record would always be saved.  Not every machine is used on every job.  I hope this helps.
0
 
wiswalldCommented:
I am thinking something like this but still trying to figure where to put it.



If MsgBox("Do you want to save? (click 'No' to undo)", vbYesNo, "Save") = vbYes Then
'Save
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
Else
'Undo
Me.Undo
End If
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
wiswalldCommented:
Or on your navigation button for new put

If Me.Field2 = False Then
Me.Undo
End If
0
 
alliedtechAuthor Commented:
The main form has numerous data entry fields such as Date, Job #, etc...

My original thought was set a default MachineID for in each subform and then to incorporate code behind the "save" command button that would check the values of the subforms, and if they were null, then set the MachineID as null.  Does this sound like the right path?
0
 
wiswalldCommented:
That is what I was getting at. Basically I took a field on the form other than the machine ID that would normally be filled out, check for a value, and if null undo any changes (not save)
0
 
alliedtechAuthor Commented:
Yea - I will work on that and post if I have any troubles.  Thanks.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now