Advertisement

09.14.2007 at 01:36AM PDT, ID: 22828340
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

global function, callingform.name, callingfield.value (Access VBA)

Asked by Angelp1ay in Microsoft Access Database, VB Database Programming

Tags: , , ,

I'm trying to optimise two simple functions in Access VBA.

(1) The first is a simple database activity logging function. When an event is triggered on any form I call a global function (i.e. stored in a module) "dms_log" which just writes some information into a log table. The function is pretty simple:

Public Sub dms_log(strForm As String, strAction As String, strDetail As String)
    ' Single quotes in expressions break our sql execute syntax
    ' Replace them with double quotes which don't...
    strDetail = Replace(strDetail, "'", """")
   
    ' Add action to dms log
    CurrentDb.Execute ("INSERT INTO z_dms_log (tstmp, user_id, form, action, detail) VALUES (Now(), " & gblUser & ", '" & strForm & "', '" & strAction & "', '" & strDetail & "');")
End Sub

and I call it like this (in this example I am saving an SQL string to my "detail" column):

Call dms_log(Me.Name, "Activity Imported", strSQL)

My first question is:
--------------------------------------
Can I grab the calling form name from the global function, something like this:

CurrentDb.Execute ("INSERT INTO z_dms_log (tstmp, user_id, form, action, detail) VALUES (Now(), " & gblUser & ", '" & me.callingform.name & "', '" & strAction & "', '" & strDetail & "');")

(2) I also have a global data validation function:

Public Function validate_date(strDate As String) As Boolean
    validate_date = False
   
    If Not IsDate(strDate) Then
        MsgBox ("Please enter a valid date")
        validate_date = True
    End If
End Function

which is used like this:

Private Sub txt_date_BeforeUpdate(Cancel As Integer)
    Cancel = validate_date(Nz(Me.ActiveControl.Value, ""))
End Sub

Private Sub txt_date_AfterUpdate()
    Me.ActiveControl.Value = Format(CDate(Me.ActiveControl.Value), "dd/mm/yyyy")
End Sub

My second question is:
--------------------------------------
Can I alter the global function to something like:

    If Not IsDate(callingfield.value) Then

so that I can call it with just:

Private Sub txt_date_BeforeUpdate(Cancel As Integer)
    Cancel = validate_me
End SubStart Free Trial
[+][-]09.14.2007 at 03:43AM PDT, ID: 19890287

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09.14.2007 at 05:59AM PDT, ID: 19890977

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, VB Database Programming
Tags: vba, access, calling, function
Sign Up Now!
Solution Provided By: JDettman
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.14.2007 at 06:37AM PDT, ID: 19891282

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.14.2007 at 06:40AM PDT, ID: 19891313

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.14.2007 at 06:41AM PDT, ID: 19891324

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.14.2007 at 06:54AM PDT, ID: 19891448

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.14.2007 at 08:52AM PDT, ID: 19892651

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.14.2007 at 09:48AM PDT, ID: 19893145

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_1_20070628