Results 1 to 3 of 3
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    where best to declare a repetitive variable

    I OFTEN use a msgbox as a way of flagging 'something' to the user
    within a module, file, ... I 'might' use one several times, occasionally within a single method;

    I set them up like this:



    Code:
    Public Sub ControlMismatchFlag(frm As Access.Form)
    Dim strTitle As String
    Dim strText As String
    Dim Response as Variant
        $P[METHOD_BODY]    
        If <something> Then
             strTitle = "CONTRARY SOURCE / CONTROL PROTOCOL"
             strText = "You have a SOURCE and CONTROL PROTOCOL combination that is not possible; " _
                     & vbCrLf _
                     & "you'll need to change one or the other"
            Response = MsgBox(strText, vbInformation + vbOKOnly, strTitle)
        End If
        $P[METHOD_BODY]  
    End Sub
    and find myself adding :

    Code:
    Dim strTitle As String
    Dim strText As String
    Dim Response as Variant
    at the beginning of EACH method... (again, and again, and again)

    ?
    -> would it make more sense to DIM the variables just once (as public, at the beginning of each module) ?
    -> and if so, then would once (is a general purpose module) for the ENTIRE PROJECT ?


    with much thnx in advance,
    m.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you can make it global (in a module):
    public gsMsgTxt as string

    and never need to declare again.

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    YEAH !!!

    thnx yet again

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

Similar Threads

  1. Repetitive Subcomponent
    By Western_Neil in forum Database Design
    Replies: 3
    Last Post: 07-17-2016, 03:09 PM
  2. How to Declare Const in Access VBA
    By ped in forum Access
    Replies: 9
    Last Post: 08-07-2011, 12:14 PM
  3. How to declare Global Variable
    By ganeshvenkatram in forum Access
    Replies: 1
    Last Post: 06-16-2011, 05:18 AM
  4. Repetitive Import Problem.
    By jasonbarnes in forum Import/Export Data
    Replies: 5
    Last Post: 02-18-2011, 11:09 AM
  5. Declare a Global Variable and Use it on Forms
    By jackkent in forum Access
    Replies: 9
    Last Post: 10-07-2010, 10:19 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