By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,479 Members | 2,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,479 IT Pros & Developers. It's quick & easy.

Display Numbers Within Text

P: 4
I want to have a popup message box for certain cases.
In the field [Status] I want an event onclick that does this:
Expand|Select|Wrap|Line Numbers
  1. If [CountOfLocation]=[Class Limit] then
  2. msgbox "Class is Full"
  3. Elseif [CountOfLocation]>[Class Limit] then
  4. msgbox "You have exceeded the class allocation by [CountOfLocation]-[Class Limit].
  5. Elseif [CountOfLocation]<[Class Limit] then
  6. msgbox "There are [Class Limit]-[CountOfLocation] Available.
  7. Endif
This doesn't work; how can I mix text with field calculations in the same string???

Thanks,
Twigs.
Aug 10 '08 #1
Share this Question
Share on Google+
6 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Please remember to provide a meaningful Title for any threads started (Please Use Appropriate Titles for New Threads!). This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

ADMIN.

PS. If you post code that doesn't work fully, it helps if you explain what doesn't work and which line it fails on.
Aug 10 '08 #2

NeoPa
Expert Mod 15k+
P: 31,186
Getting on to your problem, it seems that you need to include the data stored in variables into your message strings. What you have is simply printing the names. If you want the value of the variables (in this case variables can be from all sorts of different sources : Tables, Recordsets, Forms, Local variables etc), then you need to close the string and append the result of the variable (or calculation) to the string.

String manipulation in VBA is quite forgiving. It is possible to mix a string with a numeric and the compiler will automatically cross interpret it for you. I expect this version will work for you.
Expand|Select|Wrap|Line Numbers
  1. If [CountOfLocation] = [Class Limit] Then
  2.   MsgBox "Class is Full"
  3. ElseIf [CountOfLocation] > [Class Limit] Then
  4.   MsgBox "You have exceeded the class allocation by " & _
  5.          [CountOfLocation] - [Class Limit] & ".".
  6. ElseIf [CountOfLocation] < [Class Limit] Then
  7.   MsgBox "There are " & [Class Limit] - [CountOfLocation] & _
  8.          " places available."
  9. End If
Welcome to Bytes!
Aug 10 '08 #3

NeoPa
Expert Mod 15k+
P: 31,186
As a last point (more preaching I'm afraid - but sensible advice nevertheless), it's a good idea whenever requesting assistance that involves posting code, to compile the code first and Copy / Paste in your actual tested code.

People are likely to be understandably irritated if they see you have not taken these basic precautions before posting.
Aug 10 '08 #4

P: 4
Thank you NeoPa - I will make sure that I include my code and compiler errors next time:)

Twigs
Aug 10 '08 #5

NeoPa
Expert Mod 15k+
P: 31,186
No worries Twiggy. I guess that solved all your problems then?
Aug 10 '08 #6

P: 4
Thanks and yes, that worked!

Twigs
Aug 10 '08 #7

Post your reply

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