Results 1 to 5 of 5
  1. #1
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152

    Module to be run by macro to validate

    Hello.



    I was wondering if I can use a seperate MODULE which is run by a macro to validate a form?

    The following code is sited within the Event procedure of a form, but I really would prefer this to be in a seperate Module. Which is run by a macro using a 'complete survey' button on the form?

    is this possible? I.e. Renaming the top of the code as follows:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    To contain the form name?

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        If Me.EntranceDoorsFlats.Value <> "None" And Len(Me.EntranceDoorsFlatsQuant & "") = 0 Then
            Cancel = True
            MsgBox "Entrance Door Selected: Quant Required!"
            If Len(Me.EntranceDoorsFlatsQuant & "") = 0 Then
                Me.EntranceDoorsFlatsQuant.SetFocus
                Me.EntranceDoorsFlatsQuant.BackColor = vbRed
            End If
        End If
        If Me.EntranceDoorsFlats.Value <> "None" And Len(Me.EntranceDoorsFlatsRenewYear & "") = 0 Then
            Cancel = True
            If (Me.EntranceDoorsFlatsRenewYear & "") = 0 Then
                Me.EntranceDoorsFlatsRenewYear.SetFocus
                Me.EntranceDoorsFlatsRenewYear.BackColor = vbRed
            End If
        End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You can, but it may not be worth it. You'd have to write a function that returned a value (presumably Boolean), since the Cancel = True would have no meaning inside the function. I'm not sure about calling it with a macro either. You can, but I don't know if you can cancel the update in a macro (I don't use them). The function would have to accept the form name as a parameter, and all the "Me" references would have to use that, as Me can't be used in a standard module. Given that presumably different forms would have different controls/fields to be validated, I'm not sure it would be worth it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152
    Ok. I will keep it within the form.

    But is there a way then to save the form partially completed without the validation rules popping up. Then have them run at the end from a seperate button/macro.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Sorry, missed the follow up question. Did you sort it out? I'm not sure what you're trying to do. You should be able to enforce any type of business rule, with the right logic.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152
    Yeah thanks I have sorted it all now.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 01-12-2011, 12:43 PM
  2. Creating Macro from Module
    By Harley Guy in forum Modules
    Replies: 1
    Last Post: 11-08-2010, 07:44 AM
  3. Running module from Macro
    By Harley Guy in forum Modules
    Replies: 6
    Last Post: 10-27-2010, 11:05 AM
  4. how to validate the first line of address
    By dunners92 in forum Access
    Replies: 1
    Last Post: 03-15-2010, 09:53 PM
  5. How to validate dynamically generated text box
    By TheFuzzball in forum Forms
    Replies: 1
    Last Post: 10-24-2009, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums