Use the following function to test if the Division name has already been
entered. If not, the function returns a zero-length string, in which case,
you use an InputBox to get the Division name from the user. Then call the
function again, only this time, supplying the Division name as a parameter.
Whenevr you want to use the Division name, for example, to specify the
form's Caption property, use it like so:
Me.Caption = GetSetDivision()
If this approach doesn't suit, let me know, because I can give you a class
that gets a truckload of information from the server. Often administrators
store a Division name (or something that you can use as one), which can be
retrieved from the server.
Public Function GetSetProp(vProperty As Variant, _
Optional vValue As Variant = "") As Variant
Dim prp As Property
Dim db As Database
On Error Resume Next
If Len(Trim(vProperty)) = 0 Then GoTo Proc_Exit
Set db = CurrentDb
'Attempt to get or set the property's value.
'If it doesn't exist, an error 3270 "Property not found" will occur.
If vValue = "" Then
GetSetProp = db.Containers(1)(3).Properties(vProperty)
Else
db.Containers(1)(3).Properties(vProperty) = vValue
End If
If Err <> 0 Then
'The property doesn't exist.
On Error GoTo Proc_Err
If vValue = "" Then
'Since we're not setting the property, return nothing.
GetSetProp = ""
GoTo Proc_Exit
Else
'The property doesn't exist, create it.
Set prp = db.CreateProperty(vProperty, dbText, vValue)
'Debug.Print db.CreateProperty(vProperty, dbText, vValue).Name
'Append it to the collection
db.Containers(1)(3).Properties.Append prp
'Now read the property
GetSetProp = db.Containers(1)(3).Properties(vProperty)
End If
End If
Proc_Exit:
'Clean up
On Error Resume Next
Set prp = Nothing
Set db = Nothing
Exit Function
Proc_Err:
DoCmd.Beep
MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & _
Err.Description, vbOKOnly + vbExclamation, _
"Could not get/set property"
Resume Proc_Exit
End Function
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html