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 September 6th, 2006, 01:17 PM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default module?

Hi,

I'm new to using modules so I don't know how to fix what I'm doing wrong. Basically, I want a Yes/No Message box to run on exit from a required field. I have five of these fields, so I'd rather not have to copy/paste the same stuff five times but rather call the same code from a module. I'd like to assign names in the OnExit sub then just call the module. Regular hardcoding works just fine, it's just when I'm trying to assign aliases that thing stop working, specifically I get a "Argument not optional" error at the line in red below. I know this is wrong, but how should it be coded? And can I even do this this way?

Also, any good online reference for beginner module-users would be much appreciated. Thanks!


On Exit sub
Private Sub StudyID_Exit(Cancel As Integer)

Dim stDocName As String
stDocName = "StudyID"

Dim stExit As Integer
stExit = StudyID_Exit

Call Clear(Me)

End Sub

module
Public Sub Clear(objform As Form)

Dim stDocName As String
Dim stExit As Integer

If IsNull(objform.stDocName) Or objform.stDocName = "" Then
stExit = MsgBox("A required field is missing. You need to fill in the field or you will lose the record. Do you want to keep this record?" _
     , vbYesNo, "Stop")
  If stExit = vbYes Then
         DoCmd.CancelEvent
  ElseIf stExit = vbNo Then
       DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
       DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
       If SelTop = 1 Then
            DoCmd.GoToRecord , , acNext
            StudyID.SetFocus
       Else
            DoCmd.GoToRecord , , acPrevious
            StudyID.SetFocus
       End If


End If
End If
End Sub



 
Old September 7th, 2006, 09:12 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all, I don't see any line in red! Keep in mind that most of the time your messages will be viewed as just plain text.

You really need to brush up on the idea of variable scope. Any of the beginning Access VBA books by Wrox should be quite useful.

Without getting too heavily into your code I would suspect that it has a problem with the line:

stExit = StudyID_Exit (the red one?)

It probably thinks that you are calling this routine without the parameter (and as a function!).

-Phil-
 
Old September 7th, 2006, 11:10 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that was the line in red, actually.

And I have been poring over the Wrox Beginning Access VBA book -- I wouldn't have written a question to a forum if I'd found my answer there. But I seem to have found a way around it without having to fiddle with a module, so nevermind. Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
module umeshtheone Beginning VB 6 2 May 17th, 2007 05:48 AM
module umeshtheone VB Databases Basics 1 May 14th, 2007 01:41 PM
new module FT BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 March 15th, 2007 06:06 AM
Module sohrabus ASP.NET 2.0 Professional 1 September 1st, 2006 12:26 AM
Module / Query Help mmcdonal Access VBA 1 November 30th, 2004 01:02 PM





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