Hi,
I have had a similar question answered but don't understand code sufficiently to adapt it myself. Can someone please help and write the code I need?
I have a date field called Received, and when a date is entered in this field, I want another field called Action to be compulsory or required. The Action field is a drop down box (Combo?).
I am assuming it is an AferUpdate event, but I may be wrong.
Thanks so much for the help I get from this forum - the answers are supportive and easy to use!
Marcella
8 3556
There are a couple of ways to handle this situation, but in my opinion, the most efficient method would be in the BeforeUpdate() Event of the Form: - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Dim strMsg As String
-
-
strMsg = "If you have a Date in the Received Field, then you must " & _
-
"also enter a corresponding value in the Action Field"
-
-
If Not IsNull(Me![Received]) Then
-
If IsNull(Me![Action]) Then
-
MsgBox strMsg, vbExclamation, "Missing Value in Action Field"
-
Cancel = True
-
End If
-
End If
-
End Sub
There are a couple of ways to handle this situation, but in my opinion, the most efficient method would be in the BeforeUpdate() Event of the Form: - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Dim strMsg As String
-
-
strMsg = "If you have a Date in the Received Field, then you must " & _
-
"also enter a corresponding value in the Action Field"
-
-
If Not IsNull(Me![Received]) Then
-
If IsNull(Me![Action]) Then
-
MsgBox strMsg, vbExclamation, "Missing Value in Action Field"
-
Cancel = True
-
End If
-
End If
-
End Sub
Hi ADezii,
Brilliant! Thanks for the code. I was a bit nervous because I already had a form_BeforeUpdate event happening, but I put it in and it worked. Then I started to reply with questions in my efforts to understand what you did but then worked those out.
However, what does the [& _] do in the string message? I thought it might force a second line in the message box - but it doesn't. Do you know how I can break a message into two lines - both in Code and when I set up a Message Box in the Properties sheet?
I'm in Access 2003.
Thanks again!
marcella
Try:
strMsg = "If you have a Date in the Received Field, then you must " & vbCrLf & _
"also enter a corresponding value in the Action Field"
Hi ADezii,
Brilliant! Thanks for the code. I was a bit nervous because I already had a form_BeforeUpdate event happening, but I put it in and it worked. Then I started to reply with questions in my efforts to understand what you did but then worked those out.
However, what does the [& _] do in the string message? I thought it might force a second line in the message box - but it doesn't. Do you know how I can break a message into two lines - both in Code and when I set up a Message Box in the Properties sheet?
I'm in Access 2003.
Thanks again!
marcella
- The combination of <Ampersand><Space><Underscore>, namely & _, is a line continuation sequence. I'll post some code to illustrate my point. All three statements will produce exactly the same results as indicated below:
- Dim strString As String
-
-
strString = "She sells seashells at the "
-
strString = strString & "seashore!"
-
-
Debug.Print "She sells seashells at the seashore!"
-
Debug.Print "She sells seashells at the " & _
-
"seashore!"
-
Debug.Print strString
OUTPUT: - She sells seashells at the seashore!
-
She sells seashells at the seashore!
-
She sells seashells at the seashore!
- As far as forcing Lines (Carriage Return/Line Feed), namely vbCrLf, in Text, again I'll post some code to illustrate my point
- Debug.Print "She" & vbCrLf & "sells" & vbCrLf & "seasheels" & _
-
vbCrLf & "at" & vbCrLf & "the" & _
-
vbCrLf & "seashore!"
OUTPUT: - She
-
sells
-
seasheels
-
at
-
the
-
seashore!
- Here is sort of a Hybrid with no Line Breaks (CR/LFs), but with the Concatenation Operator (&) and Line Continuation Character (_):
- Debug.Print "She " & "sells " & "seasheels " & _
-
"at " & "the " & _
-
"seashore!"
OUTPUT: - She sells seashells at the seashore!
- Has this helped or have I totally confused you? (LOL)!
- The combination of <Ampersand><Space><Underscore>, namely & _, is a line continuation sequence. I'll post some code to illustrate my point. All three statements will produce exactly the same results as indicated below:
- Dim strString As String
-
-
strString = "She sells seashells at the "
-
strString = strString & "seashore!"
-
-
Debug.Print "She sells seashells at the seashore!"
-
Debug.Print "She sells seashells at the " & _
-
"seashore!"
-
Debug.Print strString
OUTPUT: - She sells seashells at the seashore!
-
She sells seashells at the seashore!
-
She sells seashells at the seashore!
- As far as forcing Lines (Carriage Return/Line Feed), namely vbCrLf, in Text, again I'll post some code to illustrate my point
- Debug.Print "She" & vbCrLf & "sells" & vbCrLf & "seasheels" & _
-
vbCrLf & "at" & vbCrLf & "the" & _
-
vbCrLf & "seashore!"
OUTPUT: - She
-
sells
-
seasheels
-
at
-
the
-
seashore!
- Here is sort of a Hybrid with no Line Breaks (CR/LFs), but with the Concatenation Operator (&) and Line Continuation Character (_):
- Debug.Print "She " & "sells " & "seasheels " & _
-
"at " & "the " & _
-
"seashore!"
OUTPUT: - She sells seashells at the seashore!
- Has this helped or have I totally confused you? (LOL)!
And I did LOL! Yep - I get it.
I have made it work - but Rural Guy, I needed to put a space between the & and the underscore before it worked perfectly.
Can I force a carriage return when I set the message box in the Properties Sheet?
marcella
And I did LOL! Yep - I get it.
I have made it work - but Rural Guy, I needed to put a space between the & and the underscore before it worked perfectly.
Can I force a carriage return when I set the message box in the Properties Sheet?
marcella
Can I force a carriage return when I set the message box in the Properties Sheet?
Yes, you can force a Carriage Return/Line Feed in the Properties Box by entering the CTRL+ENTER Key Combination. Typing Hello, then CTRL/ENTER, then World!, will produce:
P.S. - Hold the CTRL Key down, then press the ENTER Key.
Yes, you can force a Carriage Return/Line Feed in the Properties Box by entering the CTRL+ENTER Key Combination. Typing Hello, then CTRL/ENTER, then World!, will produce:
P.S. - Hold the CTRL Key down, then press the ENTER Key.
You are a star! Thank you.
Marcella
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Colin Steadman |
last post by:
Part No Description Quantity
45643 Random part 10
45678 Another Random part 7
98944 And another 1
<submit button>
...
|
by: CSDunn |
last post by:
Hello,
I have a combo box (Combo7) that needs to call a function during the
After Update event of the combo box. The function resides in an Access
2000 ADP Module called MMAnswerData_code.
The...
|
by: N. Graves |
last post by:
Hello... thank you for your time.
I have a form that has a List box of equipotent records and a sub form
that will show the data of the equipment select from the list box.
Is it possible to...
|
by: windandwaves |
last post by:
Hi Folk
I am working with the TYPE property. I want to change that from 2 (byte) to
4 (long integer) for a field that already contains tons of data. How can I
do that?
The help reads:
...
|
by: Reney |
last post by:
I have a very weird problem in updating my datagrid. Please help me to solve
it. The datagrid is tied to a dataset table with five columns. Three of them
are primary key and the other two columns...
|
by: AA Arens |
last post by:
I have two tables, one consists of company info like name and phone
number.
Another table where I have to fill in the contact persons. Part of the
form is to choose the company he works for (From...
|
by: Rico |
last post by:
I have tried to access a database using asp.net. after some entries like
120+, I got an unspecified error message. Anyone know what is happening, it
seems to be stuck at the same line even when i...
|
by: Miro |
last post by:
I will ask the question first then fumble thru trying to explain myself so i
dont waste too much of your time.
Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an
index - i...
|
by: justice750 |
last post by:
Hi All,
I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
|
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,...
|
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$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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...
| | |