Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Permanently hiding a label via VBA (2003)

    What's the best way to execute the following code only once upon opening a form?
    <font color=448800> <pre>Dim cmd1 As ADODB.Command
    Set cmd1 = New ADODB.Command
    With cmd1
    .ActiveConnection = CurrentProject.Connection
    .CommandText = "INSERT INTO previsioni(giorno, ora) VALUES (#06/24/2006#" & _
    ", 15)"
    .CommandType = adCmdText
    .Execute
    End With
    Set cmd1 = Nothing</pre>

    </font color=448800>
    I've tried associating it with the click event of a label on the form as follows
    <font color=red> <pre>Private Sub Label30_Click()
    Dim cmd1 As ADODB.Command
    Set cmd1 = New ADODB.Command
    With cmd1
    .ActiveConnection = CurrentProject.Connection
    .CommandText = "INSERT INTO previsioni(giorno, ora) VALUES (#06/24/2006#" & _
    ", 15)"
    .CommandType = adCmdText
    .Execute
    End With
    Set cmd1 = Nothing
    Label30.Visible = False
    End Sub</pre>

    </font color=red>
    but unfortunately the visible property of the label reverts back to True when you reopen the form so the end-user could still run the code.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Permanently hiding a label via VBA (2003)

    This seems like a one-shot piece of code. Why would you want to run it on the opening of a form?

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Permanently hiding a label via VBA (2003)

    Hi Hans,
    It indeed is a one-shot. I need to add a single, missing record to a table in a back-end mdb at a distant location so I was planning on sending a front-end mdb that would carry that out.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Permanently hiding a label via VBA (2003)

    Why don't you send them a frontend with a different name than the usual one, with instructions to open it once, then delete it?

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Permanently hiding a label via VBA (2003)

    Thank you Hans, I'll follow your advice. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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