473,386 Members | 1,846 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.

Saving form with required fields

19
Hello - I have made forms which have many required fields so when a person is filling out the forms and they get interrupted they can't save it and go back to it - they have to start over.

Is there a way to save the form with written code so that they can't print it unless all required fields are entered?

Thanks for any help.

Laura
Feb 29 '08 #1
8 1898
sierra7
446 Expert 256MB
Hi Laura
You could write a function called CheckComplete that validated each of your mandatory fields and if any failed would give an error message to inform the user and prevent printing.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Function checkComplete() As Boolean
  3. checkComplete = True
  4. If IsNull(Me.txtField1) Or Len(Me.txtField1) < 2 Then
  5.     checkComplete = False
  6.     MsgBox "Field " & Me.txtField1.Name & " is incomplete", vbCritical, "Missing Data"
  7.     Exit Function
  8. End If
  9.  
  10. If IsNull(Me.txtField2) Or Len(Me.txtField2) < 20 Then
  11.     checkComplete = False
  12.     MsgBox "Field " & Me.txtField2.Name & " is incomplete", vbCritical, "Missing Data"
  13.     Exit Function
  14. End If
  15.  
  16. End Function
  17.  
The above code first test that the field is not empty and then tests that the user has not entered a prefunctory value to 'cheat' the system. You can set the length to whatever suits you. You must have both checks because an empty field is Null not zero, so doesn't fail the Len() test.

You would call this function from your print button
Expand|Select|Wrap|Line Numbers
  1.  If checkComplete = True Then 
  2.      DoCmd.OpenReport "ReportName".....
  3. Else
  4.      Exit Sub
  5. End If
  6.  

S7
Mar 2 '08 #2
Ledmark
19
Thank you so much for your reply and help. The following is the code I have for printing the for right now:

Private Sub Print_Recruitment_Report_Click()
On Error GoTo Err_Print_Recruitment_Report_Click

Dim stDocName As String

'MsgBox "value=" + RequestNumberTextField

stDocName = "Recruitment 52"
DoCmd.OpenReport stDocName, acNormal

Exit_Print_Recruitment_Report_Click:
Exit Sub

Err_Print_Recruitment_Report_Click:
MsgBox Err.Description
Resume Exit_Print_Recruitment_Report_Click

End Sub

Would I put this statement If checkComplete = True Then in front of my code?
I don't know quite how to put them together?

Thanks for any more help.
Laura

Hi Laura
You could write a function called CheckComplete that validated each of your mandatory fields and if any failed would give an error message to inform the user and prevent printing.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Function checkComplete() As Boolean
  3. checkComplete = True
  4. If IsNull(Me.txtField1) Or Len(Me.txtField1) < 2 Then
  5.     checkComplete = False
  6.     MsgBox "Field " & Me.txtField1.Name & " is incomplete", vbCritical, "Missing Data"
  7.     Exit Function
  8. End If
  9.  
  10. If IsNull(Me.txtField2) Or Len(Me.txtField2) < 20 Then
  11.     checkComplete = False
  12.     MsgBox "Field " & Me.txtField2.Name & " is incomplete", vbCritical, "Missing Data"
  13.     Exit Function
  14. End If
  15.  
  16. End Function
  17.  
The above code first test that the field is not empty and then tests that the user has not entered a prefunctory value to 'cheat' the system. You can set the length to whatever suits you. You must have both checks because an empty field is Null not zero, so doesn't fail the Len() test.

You would call this function from your print button
Expand|Select|Wrap|Line Numbers
  1.  If checkComplete = True Then 
  2.      DoCmd.OpenReport "ReportName".....
  3. Else
  4.      Exit Sub
  5. End If
  6.  

S7
Mar 3 '08 #3
Denburt
1,356 Expert 1GB
I would think that the following should work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Recruitment_Report_Click()
  2. On Error GoTo Err_Print_Recruitment_Report_Click
  3.  
  4. Dim stDocName As String
  5.       If checkComplete = True Then
  6. 'MsgBox "value=" + RequestNumberTextField
  7.  
  8. stDocName = "Recruitment 52"
  9. DoCmd.OpenReport stDocName, acNormal
  10.  
  11.       Else
  12.            Exit Sub
  13.       End If
  14.  
  15. Exit_Print_Recruitment_Report_Click:
  16. Exit Sub
  17.  
  18. Err_Print_Recruitment_Report_Click:
  19. MsgBox Err.Description
  20. Resume Exit_Print_Recruitment_Report_Click
  21.  
  22. End Sub
  23.  
Mar 3 '08 #4
Ledmark
19
Thank you so much for all your help - it is really appreciated.


I would think that the following should work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Recruitment_Report_Click()
  2. On Error GoTo Err_Print_Recruitment_Report_Click
  3.  
  4. Dim stDocName As String
  5.       If checkComplete = True Then
  6. 'MsgBox "value=" + RequestNumberTextField
  7.  
  8. stDocName = "Recruitment 52"
  9. DoCmd.OpenReport stDocName, acNormal
  10.  
  11.       Else
  12.            Exit Sub
  13.       End If
  14.  
  15. Exit_Print_Recruitment_Report_Click:
  16. Exit Sub
  17.  
  18. Err_Print_Recruitment_Report_Click:
  19. MsgBox Err.Description
  20. Resume Exit_Print_Recruitment_Report_Click
  21.  
  22. End Sub
  23.  
Mar 3 '08 #5
Denburt
1,356 Expert 1GB
Is everything working as you would like now?

If so that is awesome glad we could help nice work sierra7.
Mar 3 '08 #6
sierra7
446 Expert 256MB
Hi
Well let's hope it works OK.

What I forgot to mention was that the properties of the fields in the Table should be changed to be none mandatory.

S7
Mar 4 '08 #7
Ledmark
19
Hello again - I haven't gotten a chance to try it out yet but am wondering about the checks - do I need to write both checks for each required field? I should find someone to sit down and do it with me so I can understand what's happening. Do I put the name of the required field in where the code says Me.txtField1 or Me.txtField1.Name?

I will get this figured out and I'll let you know how it works.

Thanks so much again!

Laura


Hi
Well let's hope it works OK.

What I forgot to mention was that the properties of the fields in the Table should be changed to be none mandatory.

S7
Mar 4 '08 #8
sierra7
446 Expert 256MB
Hi again
YES, you will have to write code for each of the fields you wish to make mandatory.

YES, [txtField1] and [txtField2] represented the name of your text boxes and will have to be changed to your actual names.

NO, you don't have to do both checks if you are only checking for an entry; IsNull() will suffice.

However, users may type 'tba' (meaning 'to be advised') instead of sourcing valid data. It depends on your application and what you are trying to do.

It's quite valid to sit down with users and understand how they do the job you are trying to model in your application.

S7
Mar 6 '08 #9

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

Similar topics

6
by: S. Graefner | last post by:
Hello Folks, I'm a Relitive newbie to the blood sport of MS ACCESS. I have designed and built a database with multiple, Related, tables. The db works well, more by good luck then good planing I...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
6
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in...
11
by: kaosyeti | last post by:
i have a form that records 9 fields into a table. on that form i have a 'done' button to close the form. right now, if the form is fully filled in, but you don't press 'enter' before you click...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
3
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
0
by: Ledmark | last post by:
I had posted a question asking for help with printing only required fields on a form - both Sierra7 and Denburt answered me and gave me valuable information. I had to make it a little simpler to get...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.