473,387 Members | 1,592 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,387 software developers and data experts.

MsgBox appears if Combobox holds certain values

109 100+
Right, I have two combo boxes - let's call them cboStatus and cboResolutionDate

Basically, what I want to happen, is when a user selects a certain option from cboStatus and cboResolutionDate is blank, a message will pop up and inform the user that they need to enter a resolution date.

I can quite happily make a message box pop up when a user selects the appropriate status but can't figure out how to combine this with cboResolutionDate being blank/null/empty.

This is one of my attempts...
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboStatus_AfterUpdate()
  2. If Me!cboResolutionDate = "" And Me!cboStatus.ListIndex = 3 Or Me!cboResolutionDate = "" And Me!cboStatus.ListIndex = 4 Then
  3. MsgBox "Please enter a closure date", vbOKOnly, "Closure date missing!"
  4. End If
  5. End Sub
I've tried changing it about a bit but the end result is always the same. It's probably a simple solution and I'm missing something really obvious.

I was also thinking I could throw in a SetFocus to cboResolutionDate?

Thanks in advance!
Jan 22 '10 #1

✓ answered by TheSmileyCoder

The issue is that cboResultion="" wont work when cboResolution is null
Null and an empty string / 0 length string are NOT the same thing

There are a few different ways to work around this.
Expand|Select|Wrap|Line Numbers
  1. me.cboResolutionDate & ""=""
or
Expand|Select|Wrap|Line Numbers
  1. nz(me.cboResolutionDate;"")=""
These basicly yield the same result. The first will concatanate your strings. If cboResolution is null the result will be null+"" = ""
The second says if its null (the Nz function) then take the value of the second argument (""), and if not null then use the first argument.

So modifying your code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboStatus_AfterUpdate() 
  2. If isnull (Me.cboStatus) then
  3.   'You may or may not need to handle this case, where a user 
  4.   'Removes a value entered.
  5.  
  6. Else
  7.   'Is a data value entered?
  8.   If (me.cboResolutionDate & "")="" And (me.cboStatus.ListIndex=3 or Me.cobStatus.ListIndex=4) then
  9.     'Field is empty
  10.       MsgBox "Please enter a closure date", vbOKOnly, "Closure date missing!" 
  11.       me.cboResolutionDate.SetFocus
  12.   End If
  13. End If
  14. End Sub 

3 4910
TheSmileyCoder
2,322 Expert Mod 2GB
The issue is that cboResultion="" wont work when cboResolution is null
Null and an empty string / 0 length string are NOT the same thing

There are a few different ways to work around this.
Expand|Select|Wrap|Line Numbers
  1. me.cboResolutionDate & ""=""
or
Expand|Select|Wrap|Line Numbers
  1. nz(me.cboResolutionDate;"")=""
These basicly yield the same result. The first will concatanate your strings. If cboResolution is null the result will be null+"" = ""
The second says if its null (the Nz function) then take the value of the second argument (""), and if not null then use the first argument.

So modifying your code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboStatus_AfterUpdate() 
  2. If isnull (Me.cboStatus) then
  3.   'You may or may not need to handle this case, where a user 
  4.   'Removes a value entered.
  5.  
  6. Else
  7.   'Is a data value entered?
  8.   If (me.cboResolutionDate & "")="" And (me.cboStatus.ListIndex=3 or Me.cobStatus.ListIndex=4) then
  9.     'Field is empty
  10.       MsgBox "Please enter a closure date", vbOKOnly, "Closure date missing!" 
  11.       me.cboResolutionDate.SetFocus
  12.   End If
  13. End If
  14. End Sub 
Jan 22 '10 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Assuming you have the date in a textbox and the resolution is always on the same day, you could simply do
Expand|Select|Wrap|Line Numbers
  1. Me.tbResolutionDate=Date()
Date() returns the current date

I usually use
Expand|Select|Wrap|Line Numbers
  1. Me.tbResolutionDate=Now()
Now() returns the current Data & Time
but then format the field to "YYYY-MM-DD". I find the extra bit of time information can come in handy.
Jan 22 '10 #3
hedges98
109 100+
Awesome stuff! Thanks buddy
I just used the middle If statement from your code as the status combo box can be left blank.

Cheeeers!
Jan 22 '10 #4

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

Similar topics

1
by: Massy | last post by:
Hi all, Just a quick question... does anyone know how i can include the value of a combobox into my message that appears in my messagebox? i.e if my combobox contains USA, how do i write 'you...
1
by: laurenq uantrell | last post by:
What I'm trying to do is to re-use the values of err.number and err.description after displaying them in a MsgBox. The values seem to auto clear and not be re-usable on a second reference. For...
16
by: jhwagner | last post by:
I need to use double data entry with an MS Access database. I have read many arguments and reasons against this on this group but I have to do this. I have seen various tips on how this can be...
8
by: Dennis D. | last post by:
Preface: I have viewed the combobox control video at Microsoft.at the movies. I want to simulate an HTML combobox as a windows application combobox with 5 to 10 selections in each box. In the...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
11
by: DSR | last post by:
Help Please... I would like to populate a combo box on a form with a query that compares data from two tables. Any record that is unique in table1 should continue to populate my combobox. The...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
1
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on...
6
by: James | last post by:
Can someone explain to me what the Or does here? Dim intReply as Integer = _ MsgBox(strPrompt, MsgBoxStyle.OKCancel Or MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2, strTitle) I don't...
0
by: piercy | last post by:
Hi, Im tyring to display a dataGridView with comboBoxes on about 5 of the fields. This table is basically permissions to certain parts of my program. In the database i just store a 1 or a 0 (access...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.