One of my absolute least favorite things to do is to convert an Access application to Visual Basic. Even though the coding is oh so close, the graphical re-design of the forms is enough to give pause... especially when you start converting 1440 twips / inch . . .

In my experience the toughest part of the conversion is the physical layout of the form, since the Access and VB designs are quite different in their approach. The following Access code was written to create a shell form with the Access controls in the correct locations; all you need to do is add the data access & VB event-handling code which usually has to be modified anyway since Jet doesn't offer the same options as an enterprise rdbms.


Sub ConvertToVB(formname As String)
' note: some lines wrapped for blog reading
    Dim Q As String
    Q = Chr(34)
    '
    Dim frm As Form, ctl As Control
    '
    Open "C:\Windows\Temp\" & formname & _
      ".frm" For Output As #1
    '
    DoCmd.OpenForm formname, acDesign
    Set frm = Forms(formname)
    With frm
        Print #1, "VERSION 5.00"
        Print #1, "Begin VB.Form " & .Name
        Print #1, "   Caption         =   " & _
          Q & .Name & Q
        Print #1, "   ClientHeight    =   " & _
          .WindowHeight
        Print #1, "   ClientLeft      =   " & _
          60 ' .WindowLeft ' experimental
        Print #1, "   ClientTop       =   " & _
          345 ' .WindowTop ' experimental
        Print #1, "   ClientWidth     =   " & _
          .WindowWidth
        Print #1, "   LinkTopic       =   " & _
          Q & .Name & Q
        Print #1, "   ScaleHeight     =   " & _
          .WindowHeight
        Print #1, "   ScaleWidth      =   " & _
          .WindowWidth
        Print #1, "   StartUpPosition =   3
        For Each ctl In frm.Controls
            Print #1, "   Begin VB.";
            Select Case ctl.ControlType
                Case acTextBox
                    Print #1, "TextBox ";
                Case acComboBox
                    Print #1, "ComboBox ";
                Case acCommandButton
                    Print #1, "CommandButton ";
                Case acRectangle
                    Print #1, "Shape ";
                Case acLabel
                    Print #1, "Label ";
            End Select
            On Error Resume Next
            Print #1, ctl.Name
            Print #1, "      Height          =   " & _
              & ctl.Height
            Print #1, "      Left            =   " & _
              & & ctl.Left
            Print #1, "      TabIndex        =   " & _
              & & ctl.TabIndex
            Print #1, "      Text            =   "; & _
              Q & ctl.Name & Q
            Print #1, "      Top             =   " & _
              & & ctl.Top
            Print #1, "      Width           =   " & _
              & & ctl.Width
            Print #1, "   End"
        Next ctl
    End With
    Print #1, "End"
    '
    Print #1, "Attribute VB_Name = " & _
      & Q & formname & Q
    Print #1, "Attribute VB_GlobalNameSpace = False"
    Print #1, "Attribute VB_Creatable = False"
    Print #1, "Attribute VB_PredeclaredId = True"
    Print #1, "Attribute VB_Exposed = False"
    Print #1, "Option Explicit"
    DoCmd.Close acForm, Forms(0).Name, acSaveNo
    Set frm = Nothing
    Close #1
End Sub