DeutchBose
Board Regular
- Joined
- Mar 22, 2004
- Messages
- 83
I have a continuous form with a few memo fields...Is there a way for a user to click the text box and have the text box expand so they can see the entire field?
Function ChangeForms(ByRef NForm As String, ByRef OForm As String, Optional frmCriteria As String, _
Optional subForm As String, Optional subField As String, Optional subCriteria As String)
' this function will change from OForm to NForm
' the optional arguments allow the following
' frmCriteria - will open OForm to record according to this criteria
' subForm, subField, subCriteria - if Nform contains a subform with records
' related to a record on OForm then if these arguments are present (and correct)
' focus will move to related record on the subform
Dim subFind As Boolean
On Error GoTo Err_ChangeForms
If frmCriteria = "" Then
DoCmd.OpenForm NForm
Else
DoCmd.OpenForm NForm, , , frmCriteria
ChangeForms = True
GoTo Exit_ChangeForms
End If
subFind = Not (subForm = "" Or subField = "" Or subCriteria = "")
If subFind Then
If IsSubForm(NForm, subForm) Then
Forms(NForm).SetFocus
DoCmd.GoToControl subForm
DoCmd.GoToControl subField
DoCmd.FindRecord subCriteria
ChangeForms = True
End If
Else
ChangeForms = True
End If
Exit_ChangeForms:
If OForm <> NForm Then
If ChangeForms Then
DoCmd.Close acForm, OForm
Else
DoCmd.Close acForm, NForm
Forms(OForm).SetFocus
End If
End If
Exit Function
Err_ChangeForms:
MsgBox Err.Description, vbInformation, "Error message"
ChangeForms = False
Resume Exit_ChangeForms
End Function
Function IsSubForm(ByVal frmName As String, ByVal subfrmName As String) As Boolean
Dim frm As Form
Dim ctrl As Control
If Not (IsLoaded(frmName)) Then Exit Function
Set frm = Forms(frmName)
If IsControl(frmName, subfrmName) Then
Set ctrl = frm.Controls(subfrmName)
IsSubForm = (ctrl.ControlType = acSubform)
Else
IsSubForm = False
End If
End Function
Function IsControl(ByVal frmName As String, ByVal ctrlName) As Boolean
' returns true if ctrlName is the name of a control on the form frmName
Dim frm As Form
Dim ctrl As Control
If Not (IsLoaded(frmName)) Then Exit Function
Set frm = Forms(frmName)
For Each ctrl In frm.Controls
IsControl = IsControl Or (ctrl.Name = ctrlName)
If IsControl Then Exit Function
Next
End Function
Function IsLoaded(ByVal frmName As String) As Boolean
'returns true if a form is open in datasheet or form view
Dim frm As Form
For Each frm In Forms
IsLoaded = (frm.Name = frmName) And ((frm.CurrentView) <> 0)
If IsLoaded Then Exit Function
Next
End Function
Function SwapForms(NForm As String, OForm As String) As Boolean
' given two form names this function will try and swap them
' if succesful returns true
On Error GoTo Err_SwapForms
If Not (IsLoaded(NForm)) Then
DoCmd.OpenForm NForm
Else
DoCmd.Close acForm, NForm
DoCmd.OpenForm NForm
End If
If IsLoaded(OForm) Then
DoCmd.Close acForm, OForm
End If
SwapForms = True
Exit_SwapForms:
Exit Function
Err_SwapForms:
MsgBox Err & ": " & Err.Description
SwapForms = False
Resume Exit_SwapForms
End Function