Results 1 to 5 of 5
  1. #1
    smoothlarryhughes is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2012
    Posts
    36

    Conditional Formatting a button?

    I have a database I'm using that has a form with 3 buttons. One button clears all the tables in the database, the second button populates all the tables by pulling the data from a file, and the third button exports the data I need to an excel file. What I would like to do is have the second button change color or have a marker that would let the user know that there is data in the table. Possibly change the button color or put a note below the button that there is data in the tables. Each day the data will be cleared out and new data populated.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Replacing TableName with the actual name of one of the Tables involved:
    Code:
    Private Sub Form_Load()
     
     If DCount("*", "TableName") = 0 Then
      ButtonTwo.ForeColor = vbBlack
     Else
      ButtonTwo.ForeColor = vbRed
     End If
    End Sub
    
    Private Sub ButtonOne_Click()
     
     If DCount("*", "TableName") = 0 Then
      ButtonTwo.ForeColor = vbBlack
     Else
      ButtonTwo.ForeColor = vbRed
     End If
    
    End Sub


    Linq ;0)>

  3. #3
    smoothlarryhughes is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2012
    Posts
    36
    Quote Originally Posted by Missinglinq View Post
    Replacing TableName with the actual name of one of the Tables involved:
    Code:
    Private Sub Form_Load()
     
     If DCount("*", "TableName") = 0 Then
      ButtonTwo.ForeColor = vbBlack
     Else
      ButtonTwo.ForeColor = vbRed
     End If
    End Sub
    
    Private Sub ButtonOne_Click()
     
     If DCount("*", "TableName") = 0 Then
      ButtonTwo.ForeColor = vbBlack
     Else
      ButtonTwo.ForeColor = vbRed
     End If
    
    End Sub


    Linq ;0)>
    Do I put these in their own subs, or in the subs which are currently tied to the buttons?

    My button to clear all the tables is per the below:

    Private Sub Command2_Click()

    DoCmd.SetWarnings False
    DoCmd.RunSQL ("DELETE * FROM tblAAMRECAP")
    DoCmd.RunSQL ("DELETE * FROM tblORDERS")
    DoCmd.RunSQL ("DELETE * FROM tblPHREF")

    Beep
    MsgBox "ALL TABLES ARE EMPTY AND READY TO BE POPULATED"

    End Sub

    My button to populate all the tables is per below:
    Private Sub Command0_Click()

    DoCmd.TransferSpreadsheet acImport, 8, "tblAAMRECAP", "I:\415757_JamesRogers\PHREF_TEST\Test Files\PHREF_UPLOAD_TEMPLATE.xls", True, "AAMRECAP!"
    DoCmd.TransferSpreadsheet acImport, 8, "tblORDERS", "I:\415757_JamesRogers\PHREF_TEST\Test Files\PHREF_UPLOAD_TEMPLATE.xls", True, "ORDERS!"
    DoCmd.TransferSpreadsheet acImport, 8, "tblPHREF", "I:\415757_JamesRogers\PHREF_TEST\Test Files\PHREF_UPLOAD_TEMPLATE.xls", True, "PHREF!"

    Beep
    MsgBox "All tables have been populated with data. You can now export the files"

    End Sub

  4. #4
    smoothlarryhughes is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Sep 2012
    Posts
    36
    I put them in their own subs, and they seem to work, but only when I reopen the form...they won't update the colors live....any ideas?

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Unless you already have a Form_Load sub, you'll need to have this:
    Code:
    Private Sub Form_Load()
     
     If DCount("*", "TableName") = 0 Then
      ButtonTwo.ForeColor = vbBlack
     Else
      ButtonTwo.ForeColor = vbRed
     End If
    
    End Sub


    If you already have code in the Form_Load event, simply add that code to it. Then modify your Sub Command2 by adding this after your current code

    Code:
     If DCount("*", "TableName") = 0 Then
      ButtonTwo.ForeColor = vbBlack
     Else
      ButtonTwo.ForeColor = vbRed
     End If


    Remember that you'll have to replace 'TableName' and 'ButtonTwo' with the actual names of your Table and the second Command Button.

    Linq ;0)>

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

Similar Threads

  1. Conditional Formatting
    By riaarora in forum Access
    Replies: 6
    Last Post: 09-03-2012, 05:58 AM
  2. conditional formatting
    By michele in forum Forms
    Replies: 6
    Last Post: 02-01-2012, 01:16 PM
  3. Conditional Formatting
    By ccordner in forum Reports
    Replies: 6
    Last Post: 01-09-2012, 04:12 PM
  4. Conditional formatting
    By avarusbrightfyre in forum Forms
    Replies: 3
    Last Post: 07-01-2011, 11:18 AM
  5. Conditional Formatting
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-30-2010, 09:31 PM

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