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

after update, make another field required

52
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
Nov 15 '08 #1
8 3556
ADezii
8,834 Expert 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. Dim strMsg As String
  3.  
  4. strMsg = "If you have a Date in the Received Field, then you must " & _
  5.          "also enter a corresponding value in the Action Field"
  6.  
  7. If Not IsNull(Me![Received]) Then
  8.   If IsNull(Me![Action]) Then
  9.     MsgBox strMsg, vbExclamation, "Missing Value in Action Field"
  10.       Cancel = True
  11.   End If
  12. End If
  13. End Sub
Nov 15 '08 #2
mjvm
52
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. Dim strMsg As String
  3.  
  4. strMsg = "If you have a Date in the Received Field, then you must " & _
  5.          "also enter a corresponding value in the Action Field"
  6.  
  7. If Not IsNull(Me![Received]) Then
  8.   If IsNull(Me![Action]) Then
  9.     MsgBox strMsg, vbExclamation, "Missing Value in Action Field"
  10.       Cancel = True
  11.   End If
  12. End If
  13. 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
Nov 16 '08 #3
RuralGuy
375 Expert 256MB
Try:
strMsg = "If you have a Date in the Received Field, then you must " & vbCrLf & _
"also enter a corresponding value in the Action Field"
Nov 16 '08 #4
ADezii
8,834 Expert 8TB
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
  1. 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:
    Expand|Select|Wrap|Line Numbers
    1. Dim strString As String
    2.  
    3. strString = "She sells seashells at the "
    4. strString = strString & "seashore!"
    5.  
    6. Debug.Print "She sells seashells at the seashore!"
    7. Debug.Print "She sells seashells at the " & _
    8.             "seashore!"
    9. Debug.Print strString
    OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. She sells seashells at the seashore!
    2. She sells seashells at the seashore!
    3. She sells seashells at the seashore!
  2. As far as forcing Lines (Carriage Return/Line Feed), namely vbCrLf, in Text, again I'll post some code to illustrate my point
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print "She" & vbCrLf & "sells" & vbCrLf & "seasheels" & _
    2.             vbCrLf & "at" & vbCrLf & "the" & _
    3.             vbCrLf & "seashore!"
    OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. She
    2. sells
    3. seasheels
    4. at
    5. the
    6. seashore!
  3. Here is sort of a Hybrid with no Line Breaks (CR/LFs), but with the Concatenation Operator (&) and Line Continuation Character (_):
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print "She " & "sells " & "seasheels " & _
    2.             "at " & "the " & _
    3.             "seashore!"
    OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. She sells seashells at the seashore!
  4. Has this helped or have I totally confused you? (LOL)!
Nov 16 '08 #5
mjvm
52
  1. 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:
    Expand|Select|Wrap|Line Numbers
    1. Dim strString As String
    2.  
    3. strString = "She sells seashells at the "
    4. strString = strString & "seashore!"
    5.  
    6. Debug.Print "She sells seashells at the seashore!"
    7. Debug.Print "She sells seashells at the " & _
    8.             "seashore!"
    9. Debug.Print strString
    OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. She sells seashells at the seashore!
    2. She sells seashells at the seashore!
    3. She sells seashells at the seashore!
  2. As far as forcing Lines (Carriage Return/Line Feed), namely vbCrLf, in Text, again I'll post some code to illustrate my point
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print "She" & vbCrLf & "sells" & vbCrLf & "seasheels" & _
    2.             vbCrLf & "at" & vbCrLf & "the" & _
    3.             vbCrLf & "seashore!"
    OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. She
    2. sells
    3. seasheels
    4. at
    5. the
    6. seashore!
  3. Here is sort of a Hybrid with no Line Breaks (CR/LFs), but with the Concatenation Operator (&) and Line Continuation Character (_):
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print "She " & "sells " & "seasheels " & _
    2.             "at " & "the " & _
    3.             "seashore!"
    OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. She sells seashells at the seashore!
  4. 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
Nov 16 '08 #6
ADezii
8,834 Expert 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. Hello
  2. World!
P.S. - Hold the CTRL Key down, then press the ENTER Key.
Nov 16 '08 #7
mjvm
52
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:
Expand|Select|Wrap|Line Numbers
  1. Hello
  2. World!
P.S. - Hold the CTRL Key down, then press the ENTER Key.



You are a star! Thank you.

Marcella
Nov 17 '08 #8
ADezii
8,834 Expert 8TB
You are quite welcome.
Nov 17 '08 #9

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

Similar topics

2
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> ...
4
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...
4
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...
1
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: ...
4
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...
10
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...
1
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...
2
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...
4
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...
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:
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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.