Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 6th, 2006, 01:17 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old September 7th, 2006, 09:12 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Location: Boston, MA, USA.
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-
Reply With Quote
  #3 (permalink)  
Old September 7th, 2006, 11:10 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:04 PM.


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