473,320 Members | 1,853 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.

Mandatory / Required field

19
Hi guys

I'm trying to force the user to enter the Customername, Contact person and (tel or cell nbr). Everything's fine for the customer and contact person as i hav made the required fields on the table.

The problem is i the user doesn't enter the customername or contact person it complains but closes the screen and i don't want the application to do dat. I want it to complain then go back to the field that still needs to be entered.

I also need help with enforcing data in the tell or cell nbr field (i can't make dem required as it's fine not 2 hav 1 if the other is there)

Here's ma code

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Before closing this form you have to check if the mandotory fields (*) have been entered else complain and don't allow the user to continue
If ValidateRecord = False Then
MsgBox ("Please enter the Customer Name or Contatct")
Me.CustomerName.SetFocus
On Error GoTo Err_cmdMainScreen_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "New_Customer"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdMainScreen_Click:
Exit Sub

Err_cmdMainScreen_Click:
MsgBox Err.Description
Resume Exit_cmdMainScreen_Click
Else
MsgBox ("Done")
End If

End Sub

Ma field types are text by d way.

Thanks
Mar 6 '07 #1
8 3367
Rabbit
12,516 Expert Mod 8TB
You'll have to turn off the requirements for the two fields in your table design. You can't have them be required if they're not actually required.

You'll have to do the checks through code, which I see you've already done. If there's a problem with the code, come back and let us know what the problem is.
Mar 6 '07 #2
ADezii
8,834 Expert 8TB
Hi guys

I'm trying to force the user to enter the Customername, Contact person and (tel or cell nbr). Everything's fine for the customer and contact person as i hav made the required fields on the table.

The problem is i the user doesn't enter the customername or contact person it complains but closes the screen and i don't want the application to do dat. I want it to complain then go back to the field that still needs to be entered.

I also need help with enforcing data in the tell or cell nbr field (i can't make dem required as it's fine not 2 hav 1 if the other is there)

Here's ma code

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Before closing this form you have to check if the mandotory fields (*) have been entered else complain and don't allow the user to continue
If ValidateRecord = False Then
MsgBox ("Please enter the Customer Name or Contatct")
Me.CustomerName.SetFocus
On Error GoTo Err_cmdMainScreen_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "New_Customer"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdMainScreen_Click:
Exit Sub

Err_cmdMainScreen_Click:
MsgBox Err.Description
Resume Exit_cmdMainScreen_Click
Else
MsgBox ("Done")
End If

End Sub

Ma field types are text by d way.

Thanks
If you actually want both Fields to be required, and the Validation Fails, you must set the Cancel Argument to True in order to Cancel the Updating of the Record.
Mar 6 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. On Error GoTo Err_cmdMainScreen_Click
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5. 'Before closing this form you have to check if the mandotory fields (*) have been entered else complain and don't allow the  user to continue
  6.  
  7.    If IsNull(Me.CustomerName) Then
  8.       MsgBox ("Please enter the Customer Name")
  9.       Me.CustomerName.SetFocus
  10.       Cancel = True
  11.       Exit Sub
  12.    ElseIf IsNull(Me.ContactPerson) Then
  13.       MsgBox ("Please enter the Contact Name")
  14.       Me.ContactPerson.SetFocus
  15.       Cancel = True
  16.       Exit Sub
  17.    ElseIf IsNull(Me.telNbr) Or IsNull(Me.cellNbr) Then
  18.       MsgBox ("Please enter the Telephone or Cell Number")
  19.       Me.telNbr.SetFocus
  20.        Cancel = True
  21.        Exit Sub
  22.    End If
  23.  
  24.    stDocName = "New_Customer"
  25.    DoCmd.OpenForm stDocName, , , stLinkCriteria
  26.    MsgBox ("Done")
  27.  
  28. Exit_cmdMainScreen_Click:
  29.    Cancel = True
  30.    Exit Sub
  31.  
  32. Err_cmdMainScreen_Click:
  33.    MsgBox Err.Description
  34.    Resume Exit_cmdMainScreen_Click
  35.  
  36. End If
  37.  
  38. End Sub
  39.  
Mary
Mar 6 '07 #4
noks
19
Thanks guys.. Marry yo code's excactly what i need. Now prob. i tried changi the or to and back but i still can't get away with entering only the cell or tell nbr... i hav 2 enter them both (which is not what i want)
"ElseIf IsNull(Me.PHONE_NO) Or IsNull(Me.CELL_NO) Then"

Guys ma application / Screen still closes automatically no matter what i try. Do u think there's somethin wrong i might hav done within d application?
Mar 7 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Firstly, there is a second End If at the end of the code that needs to be removed. Sorry my error! I have made some changes. Copy and paste the following code exactly and see what happens:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. On Error GoTo Err_cmdMainScreen_Click
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5. 'Before closing this form you have to check if the mandotory fields (*) have been entered else complain and don't allow the  user to continue
  6.  
  7.    If IsNull(Me.CustomerName) Then
  8.       MsgBox "Please enter the Customer Name"
  9.       Me.CustomerName.SetFocus
  10.       Cancel = True
  11.       Exit Sub
  12.    ElseIf IsNull(Me.ContactPerson) Then
  13.       MsgBox "Please enter the Contact Name"
  14.       Me.ContactPerson.SetFocus
  15.       Cancel = True
  16.       Exit Sub
  17.    ElseIf IsNull(Me.telNbr) Then
  18.      If IsNull(Me.cellNbr) Then
  19.          MsgBox "Please enter the Telephone or Cell Number"
  20.          Me.telNbr.SetFocus
  21.           Cancel = True
  22.           Exit Sub
  23.      End If
  24.    End If
  25.  
  26.    stDocName = "New_Customer"
  27.    DoCmd.OpenForm stDocName, , , stLinkCriteria
  28.    MsgBox "Done"
  29.  
  30. Exit_cmdMainScreen_Click:
  31. Exit Sub
  32.  
  33. Err_cmdMainScreen_Click:
  34.    MsgBox Err.Description
  35.    Resume Exit_cmdMainScreen_Click
  36.  
  37. End Sub
Mary
Mar 7 '07 #6
noks
19
Wow it worked

Thanks Dol -)
Mar 7 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Wow it worked

Thanks Dol -)
You're welcome!
Mar 8 '07 #8
Hi Mary,

Great Code, it helped me as well. I'm new to access and vba so please forgive the silly questions.

That said.

I want to be able to verify that all my mandatory fields, as you code does, then once all the fields are populated trigger the rest of my code to enter the record.


After your code runs I have code to verify if this record already exists, if it does then produce a MsgBox that states the existance of the record.

I tried using If Null = False but that did not work.

Can you give an example of code and where it would be placed within the verification code?

Thanks

Bob
Feb 29 '08 #9

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

Similar topics

4
by: MT | last post by:
Hi all, this sounds like an easy enough thing to do, but after spending 45 minutes searching google and various javascript sites I can't find out how to make a textfield (textbox or whatever you...
1
by: danibecr | last post by:
Hello all, I have a form that contains a remarks field for user input and a checkbox for out of compliance orders. I need to make the remarks field mandatory after the checkbox is checked. Right...
11
by: plumba | last post by:
Hi I have a user enolment form which is users fill out to let IT know that they need setting up on 'x' systems. When the user put a cross in the 'I would like Email' checkbox I would like the...
1
by: AR123 | last post by:
Hi I have set up mandatory form fields but it dosne t seem to be working. Would appreciate it if somone could have a look. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> ...
4
by: plumba | last post by:
Let me explain.... I have a form (most of which you guys have helped me with!!). The initial problem I was having is that it was holding the data in the fields after submit, I resolved this by...
1
by: AR123 | last post by:
The mandatory form field that is not working is the TYPE OF ILLUSTRATION. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Proforma</title> <meta...
2
by: AR123 | last post by:
Hi I have set up a form. What I want to to is with the fields: Company Postcode Agency Number Policy Number I want these to be mandatory however if someone fills in the company postcode for...
1
by: ajd335 | last post by:
Hi.. there are some radio buttons,which are mandatory in my site. So how can i find whether they are filled by the user or not ..so that i can respond accordingly.(i.e if all mandatory fields are...
7
by: sva0008 | last post by:
Hi , I have a scenario in which i have four input fields in asp with the same name batchlist. I have a button called add batch . The user can add the batch by clicking the add batch button . out...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.