|
CtAUG Home Page
These are working samples of code that address a real
application. Naturally, there are many other ways of accomplishing a
solution. If you know of one, send it to us via email and we will include
it here. FB20020725.
CT0001: List Field Names and Descriptions in all Tables
This code is called from a Maintenance Form that uses a
12-Button format with a code section for each selection. When displayed in
the Immediate Window, you can see the result when a Table Field having no
description is encountered. In time I hope to be able to update the
Description Property for the Table Field from code and controls on the
maintenance form. Frank Butash/20020724
'--- Opt12 -------------------------------------------------- 10
If bOpt12 = -1 Then
OptNm = "Opt12"
On Error GoTo Err_Opt12
Dim dbs As Database, tdf As TableDef, fld As Field
' Return Database object variable pointing to current database.
Set dbs = CurrentDb
' Return TableDef object variable pointing to Employees table.
Set tdf = dbs.TableDefs!tblObjDD1
' Enumerate fields in Employees table.
With dbs
For Each tdf In dbs.TableDefs
Debug.Print
Debug.Print tdf.Name
Debug.Print "Field" & vbTab & "Description"
Debug.Print "=====" & vbTab & "==========="
For Each fld In tdf.Fields
Debug.Print fld.Name & ", " & fld.Properties("Description")
Next fld
Next tdf
End With
End If
Exit_Opt12:
Set fld = Nothing
Set tdf = Nothing
End
Err_Opt12:
Debug.Print fld.Name & ", "; Tab(20); "*** Error 3270"
Resume Next
bOpt12 = 0
Exit_SelR1_CL:
Exit Sub
Err_SelR1_CL:
MsgBox "***SelR1CL= :" & CStr(Err) & " " & Error$
Resume Next
End Sub
CT0002: Erase Form Field Data on Before_Update
The following code erases the data in the Form
Field Text1 if the text "Dean" is entered in the Field. Code
returns the cursor to the beginning of the field. Weird results are
obtained when statements from the Me!Text1.Undo down are enabled and disabled in
various combinations.
Private Sub Text1_BeforeUpdate(Cancel As Integer)
If Me!Text1.Text = "Dean" Then
MsgBox "Hello"
Me!Text1.Undo
'SendKeys "{ESC}", True
'Escape produces erratic results ...
SendKeys "{Del}", True
Cancel = True
End If
End Sub
CT0003: Get UserName, SystemName and DomainName
This code was obtained from a WSCRIPT Vbs
program that is contained in the VBScript Download on this site. The
Wscript program is WSH029a.vbs and runs like a champ. Like most VBscript
code it is easy to write and comprehend. BUT, WScript is normally only
executed by double-clicking a script file or calling it from the Command Line
Prompt. What KB279164 informs us is that the Wscript methods can be called
from VB by omitting the Wscript term in the CreateObject instruction.
To demonstrate this code, create a Button on a Form (here bBut01) and in the On_Click Event add the
following code.
Private Sub bBut01_Click()
Dim UsrName, SysName, DomName As String
Dim Wnet As Object
'Set Wnet = Wscript.CreateObject("Wscript.Network") Note that
the Wscript object is omitted in the VB code.
Set Wnet = CreateObject("Wscript.Network")
UsrName = Wnet.UserName
SysName = Wnet.Computername
DomName = Wnet.UserDomain
MsgBox "User: " & UsrName & "@" & DomName & vbCrLf & "Logged on to: " & SysName
End Sub
Ain't this GREAT!
CT0004: Get UserName, SystemName and DomainName
John Giuliano's solution will go here.
++++++++++++++++++++++++++++++++
CtAUG Home Page
+++
|