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
8 3367
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.
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.
Try this ... -
Private Sub Form_BeforeUpdate(Cancel As Integer)
-
On Error GoTo Err_cmdMainScreen_Click
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
'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 IsNull(Me.CustomerName) Then
-
MsgBox ("Please enter the Customer Name")
-
Me.CustomerName.SetFocus
-
Cancel = True
-
Exit Sub
-
ElseIf IsNull(Me.ContactPerson) Then
-
MsgBox ("Please enter the Contact Name")
-
Me.ContactPerson.SetFocus
-
Cancel = True
-
Exit Sub
-
ElseIf IsNull(Me.telNbr) Or IsNull(Me.cellNbr) Then
-
MsgBox ("Please enter the Telephone or Cell Number")
-
Me.telNbr.SetFocus
-
Cancel = True
-
Exit Sub
-
End If
-
-
stDocName = "New_Customer"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
MsgBox ("Done")
-
-
Exit_cmdMainScreen_Click:
-
Cancel = True
-
Exit Sub
-
-
Err_cmdMainScreen_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdMainScreen_Click
-
-
End If
-
-
End Sub
-
Mary
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?
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: -
Private Sub Form_BeforeUpdate(Cancel As Integer)
-
On Error GoTo Err_cmdMainScreen_Click
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
'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 IsNull(Me.CustomerName) Then
-
MsgBox "Please enter the Customer Name"
-
Me.CustomerName.SetFocus
-
Cancel = True
-
Exit Sub
-
ElseIf IsNull(Me.ContactPerson) Then
-
MsgBox "Please enter the Contact Name"
-
Me.ContactPerson.SetFocus
-
Cancel = True
-
Exit Sub
-
ElseIf IsNull(Me.telNbr) Then
-
If IsNull(Me.cellNbr) Then
-
MsgBox "Please enter the Telephone or Cell Number"
-
Me.telNbr.SetFocus
-
Cancel = True
-
Exit Sub
-
End If
-
End If
-
-
stDocName = "New_Customer"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
MsgBox "Done"
-
-
Exit_cmdMainScreen_Click:
-
Exit Sub
-
-
Err_cmdMainScreen_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdMainScreen_Click
-
-
End Sub
Mary
Wow it worked
Thanks Dol -)
Wow it worked
Thanks Dol -)
You're welcome!
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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>
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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
|
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...
| |