Results 1 to 4 of 4

Thread: help perform this action only once

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    help perform this action only once

    I need some help on the best way to code the following actions so that they only fire one time. Currently I have them in the sub form load and an error handler.

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.    
    4. On Error GoTo FormLoadError
    5.    
    6.     '---------------------------------------
    7.     'delete the flash shortcut
    8.     Dim shell As Object
    9.     Dim link As Object
    10.     Dim DesktopPath As String
    11.     Set shell = CreateObject("WScript.Shell")
    12.     DesktopPath = shell.SpecialFolders("AllUsersDesktop")
    13.     fso.DeleteFile DesktopPath & "\Agent Prospecting Presentation.lnk"
    14.  
    15.     'create a new flash shortcut
    16.     'because we are replacing the old exe
    17.     Set shell = CreateObject("WScript.Shell")
    18.     DesktopPath = shell.SpecialFolders("AllUsersDesktop")
    19.     Set link = shell.CreateShortcut(DesktopPath & "\Agent Prospecting Presentation.lnk")
    20.     'link.Arguments = "1 2 3"
    21.     link.Description = "Agent Prospecting Presentation"
    22.     'link.HotKey = "CTRL+ALT+SHIFT+X"
    23.     link.IconLocation = "C:\WestfieldInsurance\Westfield_1to1F_v1.exe,1"
    24.     link.TargetPath = "C:\MyWestfieldPresentation\Westfield_1to1F_v1.exe"
    25.     'window style 3=maximized, 2=normal
    26.     link.WindowStyle = 2
    27.     'start in
    28.     link.WorkingDirectory = "C:\MyWestfieldPresentation"
    29.     link.Save
    30.    
    31.  
    32.     'this code modifies the existing database without overwriting user data
    33.     'create new table
    34.     Call CreateConnection(objConn)
    35.         objConn.Execute "CREATE TABLE TempDocAudio(n_id  TEXT(50))"
    36.     Call CloseConnection(objConn)
    37.        
    38.    'modify Documents and Campaign tables
    39.     Call CreateConnection(objConn)
    40.        objConn.Execute "ALTER TABLE Documents ADD COLUMN n_mp3 TEXT(50)"
    41.        'cannot use default parameters with ODBC connectivity must switch to OLEDB
    42.        objConn.Execute "ALTER TABLE Documents ADD COLUMN n_wavBol TEXT(50)DEFAULT FALSE"
    43.        
    44.        'add wespak and defender columns
    45.        objConn.Execute "ALTER TABLE Campaign ADD COLUMN c_wespakOn TEXT(50)DEFAULT 1"
    46.        objConn.Execute "ALTER TABLE Campaign ADD COLUMN c_defenderOn TEXT(50)DEFAULT 1"
    47.     Call CloseConnection(objConn)
    48.    
    49.    
    50.     'delete from bios Bud Leister and Reg Stith
    51.     Call CreateConnection(objConn)
    52.         objConn.Execute "DELETE FROM Bios WHERE b_name=""Bud Leister"" OR b_name=""Reg Stith"""
    53.         'MsgBox ("deleted")
    54.     Call CloseConnection(objConn)
    55.          
    56.          
    57.          
    58. ' Error handler
    59. FormLoadError:
    60.   If Err.Number <> 0 Then
    61.         errLogger Err.Number, Err.Description, "This error created on:"
    62.         'Debug.Print errLogger
    63.         Err.Clear
    64.         Resume Next
    65.         'Exit Sub
    66.     End If
    67.  
    68. End Sub
    He who never made a mistake never made a discovery?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help perform this action only once

    Before doing anything, check to see if TempDocAudio already exists. If it does, then don't do anything else because your routine has probably already run.

    That would be my quess as to how you could tell if it had or had not been run before.

  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: help perform this action only once

    Well then the same would be true for the desktop icon path. If the path has already been set, then everything else has probably run as well.
    He who never made a mistake never made a discovery?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help perform this action only once

    Quote Originally Posted by Navarone
    Well then the same would be true for the desktop icon path. If the path has already been set, then everything else has probably run as well.
    Ok...that works too. The thing is that something won't exist before running it for the first time that will exist after running it for the first time, so as long as your procedure checks for something before doing anything, then you should be in business.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width