?
Solved

Displaying Global Variables

Posted on 2011-10-02
5
Medium Priority
?
257 Views
Last Modified: 2012-05-12
In my Delarations Module i have set a Global variable thus:

Global strEventSummary as String

This variable will be shown in various forms and updated with the number of Bookings, Participants, Observers and Confirmed Bookings as varions procedures change these elemenst.  Like taking a new booking, a payment being made (i.e. effects Confirmed Bookings), a cancellation being made etc. etc. All I need to do is change the Global value and as each form is opened the Event Summary is always up-to-date.

In the Bookings form I have a Textbox 'txtEventSummary" with the Control Source = strEventSummary

But this displays an Error saying that the textbox has an "Invalid Control Property"

Can this be resolved?

Also in the Bookings form if a new booking is made I will update the strEvent Summary Global variable but can I just then refresh the display of the txtEventSummary textbox without refreshing the whole form.

Thanks in advance of any help
0
Comment
Question by:MikeDTE
  • 2
  • 2
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 36898802
You cannot set a control source to a code variable.

You would need to use a 'Get' function to set a controlsource..

Function GetvarES()
getvarES= strEventSummary
End function

You can set the controlsource to
=getvares()

Alternatively use the form current event procedure to  set an unbound control (no controlsource)

me.txtEventSummary = strEventSummary


As for your second Q, how are you updating the variable?
0
 

Author Comment

by:MikeDTE
ID: 36898818
Thanks for the guidance - I can see how that works.

Updating the variable depends which form I am in.  All the elements of strEventsSummary are fields in the Events table.  So in the Events form where the Events table is the Record Source it is easy:

strEventSummary = jdwe_Desc & " " & jdwe_StartDate & " " & jdwe_NoPlaces & " " & jdwe_NoBookings etc

In other forms I have DLookups in Functions to get the data from the Bookings table

Function Build_No_Bookings(lngEventID As Long, strStatus As String)

    'Build Bookings total: condition: a booking record matching the EventID and without a
    'CANX status (has "OK" status)
   
    Build_No_Bookings = DCount("*", "tJDWBookings", "jdwb_Event=" & lngEventID & " And jdwb_Status=" &_
 Chr(34) & strStatus & Chr(34))

End Function

and store them in local variables and then use these local variables to rebuild strEventSummary in the same fashion as above.
0
 

Author Comment

by:MikeDTE
ID: 36898822
should have said DLookup and DCount depending on the format of the data
0
 
LVL 77

Accepted Solution

by:
peter57r earned 1000 total points
ID: 36899260
Then wherever you are calling your 'build' code you need to add...
me.txtEventSummary = strEventSummary

0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 36900027
Alternatively, you can save the value to a custom database property; they can be displayed in textboxes, using this syntax:

=GetProperty("PropName", "")

Unlike global variables, values in custom db properties persist through closing and reopening Access, which is convenient in some cases.
Option Compare Database
Option Explicit

Private dbs As DAO.Database
Private prp As DAO.Property
Private prps As DAO.Properties
Private strPropertyName As String
Private strPropertyValue As String
Private lngDataType as Long
Private varPropertyValue As Variant


Public Sub SetProperty(strName As String, lngType As Long, _
   varValue As Variant)
'Created by Helen Feddema 2-Oct-2006
'Modified by Helen Feddema 2-Oct-2006
'Called from various procedures

On Error GoTo ErrorHandler

   'Attempt to set the specified property
   Set dbs = CurrentDb
   Set prps = dbs.Properties
   prps(strName) = varValue

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
    If Err.Number = 3270 Then
      'The property was not found; create it
      Set prp = dbs.CreateProperty(Name:=strName, _
         Type:=lngType, Value:=varValue)
      dbs.Properties.Append prp
      Resume Next
   Else
   MsgBox "Error No: " & Err.Number _
      & " in SetProperty procedure; " _
      & "Description: " & Err.Description
      Resume ErrorHandlerExit
   End If

End Sub

Public Function GetProperty(strName As String, strDefault As String) _
   As Variant
'Created by Helen Feddema 2-Oct-2006
'Modified by Helen Feddema 2-Oct-2006
'Called from various procedures

On Error GoTo ErrorHandler
   
   'Attempt to get the value of the specified property
   Set dbs = CurrentDb
   GetProperty = dbs.Properties(strName).Value

ErrorHandlerExit:
   Exit Function

ErrorHandler:
   If Err.Number = 3270 Then
      'The property was not found; use default value
      GetProperty = strDefault
      Resume Next
   Else
      MsgBox "Error No: " & Err.Number _
         & " in GetProperty procedure; " _
         & "Description: " & Err.Description
      Resume ErrorHandlerExit
   End If

End Function

Public Function ListCustomProps()
'Created by Helen Feddema 3-Oct-2006
'Modified by Helen Feddema 3-Oct-2006
'Lists DB properties created in code (as well as built-in properties)

On Error Resume Next
   
   Set dbs = CurrentDb
   Debug.Print "Database properties:"
   
   For Each prp In dbs.Properties
      Debug.Print vbTab & prp.Name & ": " & prp.Value
   Next prp

End Function

==================================
Usage examples:

Private dbs As DAO.Database
Private prp As DAO.Property
Private prps As DAO.Properties
Private lngDataType As Long
Private strPropertyName As String
Private strPropertyValue as String
Private varPropertyValue As Variant

Date
====
   strPropertyName = "PropName"
   lngDataType = dbDate
   Call SetProperty(strPropertyName, lngDataType, dteStart)

   GetStartDate = CDate(GetProperty("PropName", ""))

Text
====
   strPropertyName = "PropName"
   strPropertyValue = CStr(cbo.Value)
   lngDataType = dbText
   Call SetProperty(strPropertyName, lngDataType, _
      strPropertyValue )

   strDocsPath = GetProperty("PropName", "")

Long
====
   strPropertyName = "PropName"
   lngDataType = dbLong
   Call SetProperty(strPropertyName, lngDataType, lngID)

   lngID = CLng(GetProperty("PropName", ""))

Integer
=======
   strPropertyName = "PropName"
   lngDataType = dbInteger
   Call SetProperty(strPropertyName, lngDataType, intMonth)

   intID = CInt(GetProperty("PropName", ""))

Saving to a custom property from a control's AfterUpdate event
==============================================================
Private Sub txtDate_AfterUpdate()
'Created by Helen Feddema 2-Sep-2009
'Last modified 2-Sep-2009

On Error GoTo ErrorHandler
   
   If IsDate(Me![txtDate].Value) = True Then
      dteSingle = CDate(Me![txtDate].Value)
      strPropertyName = "SingleDate"
      Call SetProperty(strName:=strPropertyName, _
         lngType:=dbDate, varValue:=dteSingle)
   End If
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & _
      Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question