Results 1 to 5 of 5
  1. #1
    Paul1960 is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2023
    Location
    The Netherlands
    Posts
    2

    How to import and run VBA code from a text file (or table) to do basically anything?

    Hi,


    I have a multi-user dB (FE-BE) and besides updates through new versions I want to be able to make minor changes that users will not be aware of like
    -update text of a local manual
    -change content of local tables


    -place a warning text now and then
    -even change/repair part of existing VBA code (maybe to fancy)


    Two approaches:
    1: place VBA code in separate text file
    2: place code in extra table in BE


    Any thoughts?

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    users can access code in BE
    you can edit a word doc (the manual) which is stored on a server, and the path is in the db, say: \\server\folder\manual.doc

    the code below will open it via:
    OpenNativeApp txtBox (where txtBox shows the path above)


    paste this code into a module


    Code:
    
    #If Win64 Then      'Public Dclare PtrSafe Function
      Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
    #else
      Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    
    
    
    
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Not much of that makes sense to me. Local tables in FE are for the individual users for things like settings and such tables are only used by them. Updating a manual should not even enter into this since the manual is linked and not embedded, yes? Any code changes are made in the FE and you distribute or enforce new versions to be uploaded. Based on some of the points listed I suspect everyone is using the same FE file, which you shouldn't be doing.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    @ranman256
    The code in post #2 will not work in 64-bit Access. I've previously posted corrections but they've not been implemented.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Paul1960 is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2023
    Location
    The Netherlands
    Posts
    2
    Thanks Micron, I admit it's on the verge. I meant highly static tables that I thought I didn't need to link to the BE. Maybe I should... Not the personal tables. And yes, everyone has a copy of FE .

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import and Conver From File Text File Into Table
    By maruli090484 in forum Import/Export Data
    Replies: 5
    Last Post: 01-19-2021, 04:25 AM
  2. Replies: 4
    Last Post: 01-11-2017, 12:18 AM
  3. Import text file to table
    By anishkgt in forum Access
    Replies: 11
    Last Post: 10-19-2014, 03:52 PM
  4. Replies: 2
    Last Post: 02-11-2014, 09:38 AM
  5. Replies: 12
    Last Post: 04-30-2013, 02:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums