Results 1 to 9 of 9
  1. #1
    Guerra67 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    9

    Access - SQL Statement that uses variables

    I am new to this so I am not sure if I am asking this correctly.
    I have a form that has multiple toggle buttons. I would like to be able to do the following when the toggle button is clicked:
    • set the date
    • set the user
    • lock both fields so that the information is not lost

    Because there are multiple toggle buttons I would like to be able to use variables.
    Here is a sample of what i have. Hopefully someone can point me in the right direction.



    Private Sub CONTRACTTgl_Click()
    CONTRACTDATE = Now()
    CONTRACTEMP = CurrentUser
    CONTRACT = "Collected"
    Me.CONTRACTDATE.Locked = True
    Me.CONTRACTEMP.Locked = True
    End Sub


    Private Sub COPYSSTgl_Click()
    COPYSSDATE = Now()
    COPYSSEMP = CurrentUser
    COPYSS = "Collected"
    Me.COPYSSDATE.Locked = True
    Me.COPYSSEMP.Locked = True
    End Sub


    Private Sub COPYUTILITYTgl_Click()
    COPYUTILITYDATE = Now()
    COPYUTILITYEMP = CurrentUser
    COPYUTILITY = "Collected"
    Me.COPYUTILITYDATE.Locked = True
    Me.COPYUTILITYEMP.Locked = True
    End Sub

  2. #2
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    I'm not entirely sure what you mean here. Your title says SQL Statement, but none of these functions have anything to do with SQL (not in an apparent way at least).

    Are you trying to condense three separate subs into one? As in, write one sub that handles CONTRACT, COPYSS, COPYUTILITY on clicks?

  3. #3
    Guerra67 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    9
    My apologies.
    Yes, I would like to consolidate the code as much as possible as the form has 30 toggle buttons and I don't want to have to keep copying and pasting the code.

  4. #4
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    Ok, there are a few options here, but first: for each sub, before you lock, you are setting these variables:

    COPYUTILITYDATE = Now()
    COPYUTILITYEMP = CurrentUser
    COPYUTILITY = "Collected"

    Where are these variables declared? Or rather, what are you doing with these variables?

  5. #5
    Guerra67 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    9
    I am trying to capture the date and time that the toggle button is clicked.
    I have not declared the variables.
    copyutilitydate is the field name of a text box (date)
    copyutilityemp is the field name of a text box (user)
    copyutility is the toggle button

  6. #6
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    Ok so first things first, you are actually setting variables, and not the textboxes. And the toggle button can only be set to True/False, not a string value. But aside from that, here are some ideas:

    1) The easiest way would be to write a common sub takes an argument and uses that to determine which fields to affect. However, this means that you would still need to write one line of code for each toggle button's On Click event.

    2) You can create an event-sink class using a class module. This is more complicated, but you can use this as a reference: http://stackoverflow.com/questions/1...s-on-userforms

    If you need more help implementing either idea, don't hesitate to ask.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What is supposed to happen (or what do you want to happen) if you click the toggle a 2nd time?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    A toggle button is usually used to set a Yes/No, Off/On, True/False entity such as a Yes/No type field or to set the value of an option group control.

    Seems a normal command button would be adequate to just set the value of a field and then lock the field.

    If you want to allow the user to unlock the fields, then toggle button would be appropriate. But if user is allowed to change the values at will, why bother locking to begin with?

    The textboxes can be locked in their setup and code can still populate the fields they are bound to.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Good question Steve. I wondered the same (mistake/changed their mind..). I'd really like to hear about the big picture - where is this being/planned to be used? Why a toggle button? Is there business description in simple terms? Is there a data model?

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

Similar Threads

  1. Pass variables from Access to Excel
    By WhatTheFrick in forum Programming
    Replies: 1
    Last Post: 04-28-2013, 12:17 PM
  2. Trouble defining variables - Access Module
    By David92595 in forum Modules
    Replies: 1
    Last Post: 11-29-2012, 07:09 PM
  3. Replies: 3
    Last Post: 10-20-2012, 11:52 AM
  4. Replies: 7
    Last Post: 02-20-2012, 07:19 PM
  5. Using VBA Variables in a SQL statement
    By saltydawg617 in forum Access
    Replies: 3
    Last Post: 07-28-2011, 02:59 PM

Tags for this Thread

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