Programtically create mdw file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Wilson

    #1

    Programtically create mdw file

    Having nothing better to do today, I decided to do something that apparently
    only Michael Kaplan knows how to do (and cannot disclose due to legal
    reasons).
    My method is really nothing more than a stupid cheat, embedding the whole
    binary contents of the file in vba code, but who needs more? It seems to
    create the file quickly and reliably and avoids using an OLE field in a
    table to do this (which some people don't like). Apart from the slightly
    large module size, I can't see any reason to avoid this method. Does anyone
    care to comment?


    Public Function CreateWorkgroup (strPath As String) As Boolean

    On Error GoTo Err_Handler

    Dim a(0 To 3327) As String
    Dim lngCount As Long
    Dim strData As String
    Dim intFile As Integer

    a(0) =
    "000100004A6574 2053797374656D2 044422020000100 0000B56E0362600 9C255"
    a(1) =
    "E9A96772403F00 9C7E9F90FF859A3 1C57FBAED30BBDF CC9D63D9E4C39F4 6AE38"
    a(2) =
    "4BEE7A6DEC37A1 D29CFA3AC828E6E F208A60A8027B36 09E4DFB18B62134 33339"

    <snip><snip><sn ip><snip><snip> <snip>

    a(3327) =
    "6A2EED6AD8861A 1B71052B9CFACCE 699FC170E04EC32 CD1D855E70B4CF6 E38D7"

    For lngCount = 0 To 3327
    strData = strData & ConvertHex(a(ln gCount))
    Next lngCount

    intFile = FreeFile

    Open strPath For Binary As intFile

    Put intFile, , strData

    Close intFile

    CreateWorkgroup = True

    Exit_Handler:
    Exit Function

    Err_Handler:
    MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
    Resume Exit_Handler

    End Function



    Private Function ConvertHex(strC ode As String) As String

    Dim lngPos As Long
    Dim strData As String
    Dim str As String

    If Len(strCode) > 1 Then
    If Len(strCode) Mod 2 = 0 Then
    lngPos = 1
    Do While lngPos < Len(strCode)
    strData = strData & Chr$(CLng("&H" & Mid$(strCode, lngPos,
    2)))
    lngPos = lngPos + 2
    Loop
    End If
    End If

    ConvertHex = strData

    End Function


  • Tom van Stiphout

    #2
    Re: Programtically create mdw file

    On Thu, 27 Oct 2005 11:03:11 +0000 (UTC), "Brian Wilson"
    <bwilson@ease.c o.uk> wrote:

    Not sure what problem you're trying to solve. I would simply ship the
    MDW file with my application.
    -Tom.

    [color=blue]
    >Having nothing better to do today, I decided to do something that apparently
    >only Michael Kaplan knows how to do (and cannot disclose due to legal
    >reasons).
    >My method is really nothing more than a stupid cheat, embedding the whole
    >binary contents of the file in vba code, but who needs more? It seems to
    >create the file quickly and reliably and avoids using an OLE field in a
    >table to do this (which some people don't like). Apart from the slightly
    >large module size, I can't see any reason to avoid this method. Does anyone
    >care to comment?
    >
    >
    >Public Function CreateWorkgroup (strPath As String) As Boolean
    >
    > On Error GoTo Err_Handler
    >
    > Dim a(0 To 3327) As String
    > Dim lngCount As Long
    > Dim strData As String
    > Dim intFile As Integer
    >
    > a(0) =
    >"000100004A657 42053797374656D 204442202000010 00000B56E036260 09C255"
    > a(1) =
    >"E9A96772403F0 09C7E9F90FF859A 31C57FBAED30BBD FCC9D63D9E4C39F 46AE38"
    > a(2) =
    >"4BEE7A6DEC37A 1D29CFA3AC828E6 EF208A60A8027B3 609E4DFB18B6213 433339"
    >
    > <snip><snip><sn ip><snip><snip> <snip>
    >
    > a(3327) =
    >"6A2EED6AD8861 A1B71052B9CFACC E699FC170E04EC3 2CD1D855E70B4CF 6E38D7"
    >
    > For lngCount = 0 To 3327
    > strData = strData & ConvertHex(a(ln gCount))
    > Next lngCount
    >
    > intFile = FreeFile
    >
    > Open strPath For Binary As intFile
    >
    > Put intFile, , strData
    >
    > Close intFile
    >
    > CreateWorkgroup = True
    >
    >Exit_Handler :
    > Exit Function
    >
    >Err_Handler:
    > MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
    > Resume Exit_Handler
    >
    >End Function
    >
    >
    >
    >Private Function ConvertHex(strC ode As String) As String
    >
    > Dim lngPos As Long
    > Dim strData As String
    > Dim str As String
    >
    > If Len(strCode) > 1 Then
    > If Len(strCode) Mod 2 = 0 Then
    > lngPos = 1
    > Do While lngPos < Len(strCode)
    > strData = strData & Chr$(CLng("&H" & Mid$(strCode, lngPos,
    >2)))
    > lngPos = lngPos + 2
    > Loop
    > End If
    > End If
    >
    > ConvertHex = strData
    >
    >End Function
    >[/color]

    Comment

    • Brian Wilson

      #3
      Re: Programtically create mdw file

      "Tom van Stiphout" <no.spam.tom774 4@cox.net> wrote in message
      news:35o1m15f3s gavjsin6p3k5r5s 73p45cb1t@4ax.c om...[color=blue]
      > On Thu, 27 Oct 2005 11:03:11 +0000 (UTC), "Brian Wilson"
      > <bwilson@ease.c o.uk> wrote:
      >
      > Not sure what problem you're trying to solve. I would simply ship the
      > MDW file with my application.
      > -Tom.[/color]

      Just passing the time of day as I'm "between contracts" (I think that is the
      term they use). Anyway I was searching the archives and found other people
      asking the same question - and it crossed my mind that if someone did
      actually need to create a workgroup file programatically , then it could be
      done using only vba code although other people have stated it is not
      possible.
      I realise that the technique is not rocket science, but it is a general
      method which might prove useful to someone who wanted to make any small
      binary automagically appear. So provided the user had not deleted the
      mdb/mde itself, then it could restore from scratch a number of small
      binaries such as icons, images or perhaps Word templates. However, as you
      see, I have not been bombarded with responses, so perhaps no-one else can
      see a use for the technique.


      Comment

      Working...