The following example inserts a string of text into a standard module:
Function InsertProc(strModuleName) As Boolean
Dim mdl As Module, strText As String
On Error GoTo Error_InsertProc
' Open module.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Initialize string variable.
strText = "Sub DisplayMessage()" & vbCrLf _
& vbTab & "MsgBox ""Wild!""" & vbCrLf _
& "End Sub"
' Insert text into module.
mdl.InsertText strText
InsertProc = True
Exit_InsertProc:
Exit Function
Error_InsertProc:
MsgBox Err & ": " & Err.Description
InsertProc = False
Resume Exit_InsertProc
End Function