473,320 Members | 1,920 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,320 software developers and data experts.

How to make sure all the fields in the form are filled before saving the record

wasseypurian
I have two forms to filled one after other
1. Project Form now referred as projform
2. Project Risk_Details Form now referred as projriskform

Now I want that all the fields to be filled in projform before I migrate to the projriskform. So I have tried to make the all the field "Required" in the table. But how can I modify the message that it displays?

Also where should I place the macro of opening the projriskform and I should display the message that entry has been stored in the table?

I have tried to place the openform macro after the saverecord(developed using the record operation of the form wizard) button but the problem is that the form migrates even when the form is not complete.


https://www.dropbox.com/s/kf4mgfgq6gl62vu/savemacro.jpg

I have even tried with after_insert event but that is not working.

I have tried after update thing as well but that also dose not seem to work as I have other things as well running in after update event

Have a look as code below
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. ' Next is used to save value for correct confirmaton message.
  4. Dim IsNewRec As Integer
  5.  
  6. Private Sub Sector_AfterUpdate()
  7. 'For the sub sector display
  8. SubSector = Null
  9. SubSector.Requery
  10. SubSector = Me.SubSector.ItemData(0)
  11.  
  12. ' Display confirmation Message.
  13. If (IsNewRec = 1) Then
  14. MsgBox "Order Added.", vbInformation, "Confirmation"
  15. Else
  16. MsgBox "Order Updated.", vbInformation, "Confirmation"
  17. End If
  18.  
  19. End Sub
  20.  
  21. Private Sub Form_Current()
  22. 'For the sub sector display
  23. SubSector.Requery
  24.  
  25. ' set newrec switch for confirmation.
  26. If (Me.NewRecord) Then
  27.     IsNewRec = 1
  28. Else
  29.     IsNewRec = 0
  30. End If
  31.  
  32. End Sub
  33.  
  34. Private Sub Form_Load()
  35. If IsNull(Sector) Then
  36.   Sector = Me.Sector.ItemData(0)
  37.   Call Sector_AfterUpdate
  38. End If
  39.  
  40. 'If IsNull(Project_Name) Then
  41.     'DoCmd.GoToRecord , , acNewRec
  42. 'End If
  43.  
  44. End Sub
  45.  
  46.  
Where shall I open the new form?
Jun 24 '14 #1
5 5961
twinnyfo
3,653 Expert Mod 2GB
wasseypurian,

There are two main ways I have seen what you want to do. neither way uses macros, and most on this forum would agree that in order to build a robust database, you need to use VBA instead of macros.

Option 1: Use the built in error trigger to require entry of the required data fields. I believe the validation rule is 2107. When the error triggers, see if the error is 2107, and then have the user correct the data entry error.

I prefer:

Option 2: Your VBA controls navigation options. Provide instructoins ont he form and in the ControlTipText property of your controls to say that certain values are required. After every control is updatedd, check to see that it is a valid entry. Once all the controls have valid entries, then enable the button that navigates to the next step in the operation. You could also do this after the fact, so that when the user clicks the button to go to projriskform, these validations are done through your VBA. If it meets all the required criteria (and no errors will fire, because you are not navigating to a new record), then open the projriskform.

Either way will work. Others here will have different preferences, but option 2, in my opinion would be preferred, because I don't like my db to generate errors, but I would rather exhaust all possible options before an error arises--this is not possible in all situations.

Work with these prionicples and let us know what you come up with and we can troubleshoot any additional details.
Jun 24 '14 #2
Can you please give an example about how to use option 2. I am sorry if this question is dumbo to ask as I am new to access.

Though I have tried to fix the things by placing condition on each fields and it worked fine as [MacroError] fired up until all the required fields were filled up.

https://www.dropbox.com/s/0n11tl6sdx16bf5/mystratey.jpg

But using the above strategy is got stuck when in another form I have imposed primary key condition so that enties in two fields cannot be same to any of the previous entry in the form.

For example : If I have already have values for field 3 & 4 as Spain and Chile. And while filling the form user again chooses Spain and Chile then primary key violation will occur but I believe this does not passes the [MacroError] condition.

https://www.dropbox.com/s/5rhj4phhhm...keyproblem.jpg

How can I check this type of error.
Jun 24 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Not a dumbo question at all.

According to Option 2 above, you would have a command button that moves to the projriskform when it is clicked. However, in the command button's properties, you set its Enabled Property to False. This will display it on the Form, but no one can click it and navigate to the next section.

Now, let's say you have four text boxes (we will call them txtBox1, txtBox2, txtBox3 and txtBox4--just for example), all of which require data in them. You can have a label on the Form that tells the user these text boxes must contain data (so at least they know). You can also have a brief message in the ControlTipText of each text box. Then, when someone hovers the mouse over that text box, a small pop up will tell them they have to put something in there.

then, in the Text Box AfterUpdate events, add this, plus an additonal sub to evaluate your text boxes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtBox1_AfterUpdate()
  2.     ValidateData
  3. End Sub
  4. Private Sub txtBox2_AfterUpdate()
  5.     ValidateData
  6. End Sub
  7. Private Sub txtBox3_AfterUpdate()
  8.     ValidateData
  9. End Sub
  10. Private Sub txtBox4_AfterUpdate()
  11.     ValidateData
  12. End Sub
  13. Private Sub ValidateData()
  14.     If IsNull(Me.txtBox1) Or _
  15.         IsNull(Me.txtBox2) Or _
  16.         IsNull(Me.txtBox3) Or _
  17.         IsNull(Me.txtBox4) Then
  18.         Me.cmdProjRiskForm.Enabled = False
  19.         'Add code to determine which text box
  20.         'is blank and notify the user
  21.     Else
  22.         Me.cmdProjRiskForm.Enabled = True
  23.     End If
  24. End Function
This is only the basics, but I can't write your code for you. Use this sample as a strating block for building specifically to your needs.

Please note, that I did not include any error handling, which should also be included in all of your VBA.
Jun 24 '14 #4
Thanks for your help :)
You just saved my life ;)
Jun 25 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Glad I could help! Let us know if we can help with anything else!
Jun 25 '14 #6

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

Similar topics

2
by: EricRobineau | last post by:
hello I have a DB with many inter-related tables (MySQL) My main table called "content" has almost only foreign keys (integers) some have a 3 level relation (ex: content->city->region->country) ...
1
by: Dave Bailey | last post by:
I am using the following code on a web form public DataView CreateEquipmentDataSource( string equipConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString() + "" string equipSelect = "Select...
5
by: ApexData | last post by:
Hello I'm trying to save data to an Existing Record in a single table. These fields are not on my Form. It is not saving the data to the record ??? Dim db As DAO.Database Dim rs As...
5
by: sara | last post by:
Hi - I have 2 new questions in a new database I'm trying to develop. The first has 6 fields on a table and allows the user to enter them on a form. The form is bound to the table. All 6...
10
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some...
10
by: Hulas | last post by:
Guys I have a form with a 'save' and 'close form' button. How do I make sure that the user has saved the record before closing it. What I am looking for is that I want to modify the 'close form'...
18
by: Marilyth | last post by:
I am using Windows XP and Access 2003. I have searched through my HUGE book & the questions here, and found some items that "might" help, but unsure still. I am still getting versed on Access. I...
5
by: slenish | last post by:
What im trying to do is cut down on saving blank records. At this moment when I hit save record it just saves a whole blank record. What I want to do is make it so when you hit save if certain...
1
by: Yousaf Shah | last post by:
Hi everybody my question is very simple (hope so) I have two forms named PatientData and NOK. PatientData form is based on table PatientData with PatientID as primary key. NOK form is based on a...
5
Seth Schrock
by: Seth Schrock | last post by:
I have a form with a subform. To save time, I have set several of the main form controls to have default values so that I don't have to edit them most of the time. The subform is often the first...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.