[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Message box if combobox is null

Posted on 2013-05-29
10
Medium Priority
?
1,224 Views
Last Modified: 2013-05-29
Trying to make a msgbox appear if a combobox is null.  Here's my code...  I've tried it in beforeupdate and afterupdate but it doesn't work.

    If IsNull(Me![cboProjectName]) Then
        MsgBox "There are no new projects."
    End If
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39204663
Try putting it in the OnCurrent event.  
This may work better too:
If Me![cboProjectName] & "" = "" Then

Open in new window

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39204674
the beforeupdate and afterupdate event of the control will only happen if;
- you update the data by entering  or deleting a character then moving on to another control.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39204679
After Update and Before Update don't run unless the user actually edits the field.  If you want to trap "no data entry", you can place your code in the Before Exit Event of the control and set that control as the first tab stop (not my favorite UI behavior, but this will keep the focus locked on that control until data is entered):

Private Sub cboProjectName_BeforeExit(Cancel as Integer)
   If IsNull(Me![cboProjectName]) Then
        MsgBox "There are no new projects."
        Cancel = true
    End If
End Sub

Open in new window

0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 48

Expert Comment

by:Dale Fye
ID: 39204823
I generally don't like to use the BeforeExit event of controls, because that forces users to perform their data entry in a specific order, which is somewhat contrary to the whole "windows UI concept".

I generally put these types of tests in the Click event of an button designed to perform some action, either the Save the record or some other action.  I also like to use the Form_BeforeUpdate event, which can be cancelled if a required field is missing a value.

It really depends on how your form is organized, is it a data entry form (if so, a "Save" button or the Form_BeforeUpdate event are probably best)?  If is is a form that allows you to generate reports or something like that, then it probably is unbound and a command button which performs some action would probably be best.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39204848
Steve,

<< MsgBox "There are no new projects." >>

The wording of your message is a little unusual.  Are you referring to the textbox portion of your combo - indicating that the user has not entered anything, or are you trying to indicate that there are no selections available in the drop-down list?

If Me.cboProjectName.ListCount = 0 Then
    MsgBox "There are no new projects." 
End If

Open in new window

0
 

Author Comment

by:SteveL13
ID: 39205796
That there are no selections available in the drop-down list.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39205814
then you can't use any of the event you mentioned.. perhaps the form's current event

private sub form_current()

if me.cboProjectName.listcount= 0 then
   MsgBox "No Project"
end if


end sub
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 39205860
Steve,

See my comment at http:#a39204848...

The On Current event that cap mentioned is a good place if you want this to be checked every time the user changes records or opens the form.

However, if you want it to be in response to some user action... place it in whatever event is actually changing the rowsource of the combo.

For example if you have code filtering that combo in some other control's After Update event, place that code AFTER filtering the combo in the same After Update event.   This may be VBA that sets the rowsource property... or it may simply be a requery statement...

So you may need something like this:

Me.cboProjectName.rowsource = ... etc
If Me.cboProjectName.ListCount = 0 Then
    MsgBox "There are no new projects." 
End If

Open in new window


Or this:

Me.cboProjectName.Requery
If Me.cboProjectName.ListCount = 0 Then
    MsgBox "There are no new projects." 
End If

Open in new window

0
 

Author Comment

by:SteveL13
ID: 39206170
I put your code in the ongotfocus event and it worked.... (THANKS!)

Me.cboProjectName.Requery
If Me.cboProjectName.ListCount = 0 Then
    MsgBox "There are no new projects."
End If
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39206193
Steve,

Glad to help out.

Just a note -  if you are using the GotFocus event to trigger this, that Me.requery is probably not needed.

I'd assume you already have the requery or something similar elsewhere in your existing code if your combo box is being filtered.

If Me.cboProjectName.ListCount = 0 Then
    MsgBox "There are no new projects." 
End If

Open in new window


These three lines are meant to be a supplement to whatever is filtering your combo box.  The location of the code is up to you -- based on what actions should trigger it (and the gotfocus or enter events are of course good choices if it responds the way you want :)  )
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question