473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

mainform and subform (entering data)

mseo
181 100+
hi,
I have mainform with two cmdbuttons:
1- Save
2- Add Detail
the mainform has subform which is set to invisible, if I click Add Detail the subform appears, if not and user clicked Save the fields in the mainform will move to new blank record without having any details
what I need to do, when the user click save and the fields in the subform is not filled, In this case I need the save action (moving to next blank record) to be cancelled
I had some suggestion that prompt me to write the code. if the subform visible make the save button enabled if invisible make it disabled , but when I did so, I found that the user click Add Detail to make the subform appeared then click Save
so I need to cancel or delete the data saved in the mainform if the subform has no record.
because when I move the focus from the mainform to the subform the data in the mainform will be already saved after the focus on the subform, even if the user click exit the data in the mainform will be still saved, and this will be big problem for me.because of two reasons:
1- as soon as the user click save record selector will move to new record.
2- if click Exit the form will be closed and mainform data will be still saved
so I need to do this:
1- if click save and subform with no data then setfocus the subform, if subform filled , move to add new record
2- if click exit and subform with no data then delete the data saved in the mainform, if not, delete all the data in mainform and subform
please I need any help with this
appreciate any suggestions
May 30 '10 #1
5 3919
slenish
283 100+
Hi Mseo,

I will try to help you out with some of this. What you can do is try this code in your main form or your subform on close or if a command button is clicked to close the form. You set it to check if any boxes are left blank, if so then it will propt the user that it if they close the form it will delete all the information, and you wont get a blank record. The middle line that starts with (Forms! ) this is so you can reset the focus of the cursor back to your main form or sub form and a text box/ combo box you choose.

Hope this helps :)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. On Error GoTo Err_Form_Close
  3.  
  4. If Me.(TextBox) = "" Then
  5. DoCmd.RunCommand acCmdUndo
  6. Cancel = True
  7. Response = acDataErrContinue
  8. End If
  9.  
  10. Forms!YourMainForm!YourTextBox.SetFocus
  11.  
  12. Exit_Form_Close:
  13.     Exit Sub
  14.  
  15. Err_Form_Close:
  16.     MsgBox Err.Description
  17.     Resume Exit_Form_Close
  18.  
  19.  
  20. End Sub
  21.  
May 30 '10 #2
mseo
181 100+
@slenish
ok, slenish
thank you
but as soon as I lost the focus of the mainform and moved to the subform, that means that the data that inserted into the mainform is saved, and setfocus back to mainform that doesn't mean that i can easly delete the data saved or cancel the action.
Jun 1 '10 #3
mseo
181 100+
I need any suggestion about if I click Exit I want to delete the data entered in the mainform and sub form if I setfocus on the subform which means cancel the entire data entry operation
appreciate any suggestions
Jun 8 '10 #4
slenish
283 100+
Mseo,

Try using this same code in your Private Main Form_Close function.

Just take out the SetFocus part since you dont need to set any focus. Try using it in both parts so if you close either the main form or just the sub form it should delete the information for both.
Jun 9 '10 #5
mseo
181 100+
hi,
I need to do this on Exit cmdbutton
if I click Exit and mainform is filled then undo the entred data in the mainform and it is quite simple to be done
but the dilemma, what about if i setfocus on the subform after filling the mainform?
as soon as I setfocus on the subform the data in the mainform is already saved, so if I want to click Exit to cancel the entire data entry operation ( mainform and subform)how can I delete the entered data in the mainform on click exit
in other words
on click exit I need to delete the data in mainform and subform
thanks
Jun 10 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: William Bradley | last post by:
At the moment I am having a problem with relationships and updating tables. The following is a production run. Table1 -- MainFormTable1 -- Basic Table Record Table2 ----SubFormTable2 --...
0
by: Sabine Oebbecke | last post by:
Hi Experts! I have several forms and reports where controls get their values with 'Forms!MainForm!Control' or 'Forms!MainForm!Subform!Control' resp 'Forms!MainForm!Subform.Form!Control' which...
3
by: Ellen Manning | last post by:
Using A2K. I've got a mainform with a subform (subfrm1). There's a subform within that subform (subfrm2). When an amount is entered on the mainform, I want that amount to appear on subfrm1 and...
0
by: Dalan | last post by:
I'm sure there is a workaround for this, but haven't found it yet. I have a mainform with two subforms and after one or both of the subforms are updated, then clicking the Refresh button on the...
0
by: P Mitchell | last post by:
Hello I would like someone to be able to help with the updating of data in a lookup list in a subform. In short, is their a VB instruction that is the equivalent of performing the action of...
2
by: jayderk | last post by:
I am writing an application that has I/O entering data in a text field. My question is. does the event "textchanged" fire as soon as the data starts changing.. for example... if 12345 is being...
1
by: Savas Ates | last post by:
i was given an url bla bla.wsdl i am asked for entering data using this wsdl url? is it possible? how can i do it? must i use asp.net werb services .. any url or example or way t solve it...
7
by: FNA access | last post by:
I have a mainform that has a subform in the detail section and a subform in the footer section.(Both subforms are in datasheet view) When I click the navigation button to create a new record on the...
4
by: lulaging2000 | last post by:
After entering data in the first text box I want to make the second text box to get focus when the Enter key is pressed instead of Mouse and Tab control. Is there any way to do that by making the...
3
by: cheweedog | last post by:
I have a form that contains 1 subform. Everything works fine until I tab into a textbox in the bottom of the main form. The data in the subform disappears on the form, but the table is updated. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.