Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2004, 06:29 AM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default msgbox

I have two text boxes on a form. mycontrol1 mycontrol2
Before the user save those values to a table, I would like a message box to pop up, once for each control, that asks the user to verify the entry and its spelling.

In other words can a messagebox contain a value from a textbox on a form? And how?

Thanks, bph

 
Old February 6th, 2004, 10:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by bph
In other words can a messagebox contain a value from a textbox on a form? And how?
Yes, what you can do if you want to verify each and every field (I hope there are not many of them! ) is something like this:
Code:
   Dim ctlMyControl as Control
   Dim varAnswer as Variant

   'Cycle through all the controls in the form.
   For Each ctlMyControl in Me

      'Only work with textboxes, not other controls.
      If ctlMyControl.ControlType = acTextBox Then

         'Point to the control and highlight it.
         ctlMyControl.SetFocus
         ctlMyControl.BackColor = vbYellow

         'Ask the question.  Control's name is on top of dialog box.
         varAnswer = MsgBox("Are you sure the entry and its spelling are correct?", _
         vbQuestion + vbYesNo, ctlMyControl.Name)

         'There is an error.  Exit and leave the cursor there.
         If varAnswer = vbNo Then
            ctlMyControl.BackColor = vbWhite
            Exit Sub
         End If
      End If
   Next
   ctlMyControl.BackColor = vbWhite

If you answer "Yes" to the question for all textboxes, your cursor will end up sitting at the last one.

I haven't tested this so be wary of syntax errors!

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old February 6th, 2004, 03:00 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Nice Work!!!! It worked!!:D THANKS GREG!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Msgbox rwalker ASP.NET 1.x and 2.0 Application Design 28 March 20th, 2008 01:23 PM
Msgbox Help darrenb Access VBA 2 June 8th, 2007 12:53 AM
MsgBox prabodh_mishra Pro VB 6 1 December 29th, 2006 11:51 AM
msgbox Ramakrishna.G General .NET 3 September 14th, 2004 02:17 AM
help with Msgbox helmekki Excel VBA 2 June 25th, 2004 08:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.