Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    Unanswered: CurrrentUser/DateTime.Date in Access Module

    I am trying to use the CurrentUser() and DateTime.Date functions in an access module. I try and track who changes information on forms, and if they try to change who changed the information I want it to change back. Below is the code I have. (It all works if I include it in each forms VBA code.) I just cant seem to get it to work in a module.


    Option Compare Database

    Dim TDate
    Dim CUser As String

    Public Function DataChange()

    On Error GoTo DataChange_Err


    CUser = CurrentUser
    TDate = DateTime.Date
    ChangeDate.Value = TDate
    WhoChange.Value = CUser

    DataChange_Exit:
    Exit Function

    DataChange_Err:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description
    Resume DataChange_Exit
    End Function

    Public Function NoDateChange()
    MsgBox "You cannot change this information!", vbOKOnly, "Warning!"
    ChangeDate.Value = TDate
    End Function

    Public Function NoUserChange()
    MsgBox "You cannot change this information!", vbOKOnly, "Warning!"
    WhoChange.Value = CUser
    End Function

    Then on the forms I use the 'txtboxname'_OnChange() function to call the above public functions.

    Thanks in advance for the help.
    Jarvis
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you need to tell your public function where to stuff the data?
    one possibility:

    private sub TextBox1_Click()
    dim targetBox as textbox
    set targetBox = TextBox1
    NoDateChange targetBox
    ...etc

    and modify your public functions (why functions if they return nothing?):

    Public Sub NoDatechange(aBox as textBox)
    aBox = whateverYouWantToSetItTo
    ...etc
    currently using SS 2008R2

  3. #3
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    Okay

    I am pretty sure I understand what you are saying. Give me just a few minutes to try this out. Thanks for the help.
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

  4. #4
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    I changed my coding b4 you posted your reply

    Here is the changed coding. Just in case it shows what I am trying to do a bit more. (or it could just show how much of a noob i am )

    Here it is:

    Option Compare Database

    Dim TDate
    Dim CUser As String
    Dim AForm As Form

    Public Function DataChange()

    On Error GoTo DataChange_Err

    Set AForm = Screen.ActiveForm

    CUser = CurrentUser
    TDate = DateTime.Date
    [Forms]![AForm]![ChangeDate] = TDate
    [Forms]![AForm]![WhoChange] = CUser

    DataChange_Exit:
    Exit Function

    DataChange_Err:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description
    Resume DataChange_Exit
    End Function

    Public Function NoDateChange()
    Call DataChange
    MsgBox "You cannot change this information!", vbOKOnly, "Warning!"
    End Function

    Public Function NoUserChange()
    Call DataChange
    MsgBox "You cannot change this information!", vbOKOnly, "Warning!"
    End Function
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

  5. #5
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    Question?

    Do I need to have a Call NoDateChange targetbox or just type it as you have it?

    Originally posted by izyrider
    you need to tell your public function where to stuff the data?
    one possibility:

    private sub TextBox1_Click()
    dim targetBox as textbox
    set targetBox = TextBox1
    NoDateChange targetBox
    ...etc

    and modify your public functions (why functions if they return nothing?):

    Public Sub NoDatechange(aBox as textBox)
    aBox = whateverYouWantToSetItTo
    ...etc
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

  6. #6
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    Didnt work for me :-/

    Hmm the code that you have provided for me, either doesnt work for me, or I am doing it incorrectly. Is there any way you could explain in more detail?


    Thanks,

    Also if there is anyone else who can comment please do!

    Thanks a bunch,
    Jarvis

    Originally posted by izyrider
    you need to tell your public function where to stuff the data?
    one possibility:

    private sub TextBox1_Click()
    dim targetBox as textbox
    set targetBox = TextBox1
    NoDateChange targetBox
    ...etc

    and modify your public functions (why functions if they return nothing?):

    Public Sub NoDatechange(aBox as textBox)
    aBox = whateverYouWantToSetItTo
    ...etc
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

  7. #7
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sorry for the delay - i had to go out.

    i haven't actually tried passing the textbox object to a public sub (or function) in a module, but it works fine with a public function in a form.

    you can see what i'm gettting at with this sending the object name to a form. sorry i don't have time right now to experiment with doing the same with a public routine.

    izy
    currently using SS 2008R2

  8. #8
    Join Date
    Mar 2004
    Location
    Nashville, TN
    Posts
    557

    Okay

    I still havent figured it out yet. I will try again in a while. Right now I need to get something else straight.


    Thanks for everything,
    Jarvis
    Have you ever thought about thinking on purpose?

    Jarvis Stubblefield
    Patriot Designs
    Web/Database Development and Consulting
    The-Patriot.net by Patriot Designs

Posting Permissions

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