Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function in Modules (97)

    Hi, I have a function in the modules area, which asks for a password and returns a True or False value.

    I am calling this function from a form, but after the function runs, I get a 'Save As' dialog box come up asking me whether or not to save the form! What is causeing this I do not know, I have other Subs in this module which work fine, is there something about functions returning values that cause this?

    Regards
    Thanks,

    pmatz

  2. #2
    Lounger
    Join Date
    Mar 2002
    Location
    St Albans, Hertfordshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function in Modules (97)

    M

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function in Modules (97)

    this is the code on the form. it triggers the function when certain keys are pressed:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim bool As Boolean
    If Shift = 3 And KeyCode = 123 Then P1.T
    If bool = True Then Me.cmdUpdate.Enabled = True
    End Sub

    This is the module code, its very simple. Its in module P1:

    Public Function T() As Boolean
    Dim strPass As String
    strPass = "Matz"
    If InputBox( "Password Required") = strPass Then
    T = True
    Else
    T = False
    End If
    End Function

    i dunno if this helps
    Thanks,

    pmatz

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Function in Modules (97)

    I don't see why this should cause a "Save As" dialog, but I don't understand how this could work anyway, since you don't assign a value to bool. I would use

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = (acShiftMask Or acCtrlMask) And KeyCode = 123 Then
    Me.cmdUpdate.Enabled = P1.T
    End If
    End Sub

    Are you sure there is no other code involved?

  5. #5
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function in Modules (97)

    Hi Hans, yes, that was my mistake, in my code i did as you said, but when i pasted it over i messed it up!

    I dont see any other code involved,

    Me.cmdUpdate.Enabled = P1.T

    is precisiley what i have. very odd. have a look? i managed to strip my database down ( use of compact database has been found!!)
    Attached Files Attached Files
    Thanks,

    pmatz

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Function in Modules (97)

    The key combination you have chosen (something with F12) also acts as "Save As" in Access. To prevent the built-in action from being executed, set the KeyCode to 0:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = 3 And KeyCode = 123 Then
    Me.cmdUpdate.Enabled = P1.TechSupp
    ' Cancel built-in action
    KeyCode = 0
    End If
    End Sub

  7. #7
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Function in Modules (97)

    fair play! i wouldnt have guessed that for ages!

    that's like yesterday i was freakin out over the DMax function, because it was tellin me 8 was bigger that 167!

    ... till i realised that the field i was checking was a text field, not a number field.....

    thanks Hans.
    Thanks,

    pmatz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •