Results 1 to 5 of 5
  1. #1
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    82

    Chessboard layout

    Hi all,



    I'm doing a little quirky fun activity for my office that likes to play chess.

    I settled on an approach where the form is continuous and linked to an 8x8 table.

    Most things are coming together quite nicely, but I'm a little curious about how to get the square colouring

    My initial though was to use conditional formatting by determining the row ID (Mod 2) or using on paint. However, it turns out I have no idea how to write a mod 2 to paint for squares

    So before I crush my soul on trying to work it out, i'm going to ask if anybody has done anything particularly daft like this and how did you approach it.

    Otherwise, how might I modify the textbox back colour to alternate black and white down 8 rows and across 8 columns.

    Cheers

    and thanks for tips

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    One way: You can select 32 text boxes by holding down CTRL and clicking the 32 white boxes, then use the property sheet to set BG for all 32 in one swell foop. Then the other 32 for black.

  3. #3
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    i'm going to ask if anybody has done anything particularly daft like this and how did you approach it.
    I have an app i use to make calendars mainly because it's such a pain to get 42 text boxes and name them in a way so you can loop through them.

    Modified to do an 8X8 grid. Just open a form named Form1 in design mode and run this code from a standard module.

    Code:
    Sub CreateTextboxesOnly()
        Dim i As Integer
        Dim y As Integer
        Dim j As Integer
        Dim ctlTBPrefix As String
        Dim StartingPosTop As Double
        Dim PosLeft As Double
        Dim NextRowPos As Double
        Dim BlankSpace As Double
        Dim NextColumn As Double
        Dim ctlWidth As Double
        Dim TBoxHeight As Double
        Dim frm As Form
    
    
        Set frm = Forms("Form1")
    
    
        Dim ctlTB As Control
    
    
        ctlTBPrefix = "Tbx"
        ctlWidth = 2000
        TBoxHeight = 1440
        StartingPosTop = 1000
        PosLeft = 1000
        BlankSpace = 100
        NextColumn = 1000
        NextRowPos = 1000
    
    
        y = 0
    
    
        For j = 1 To 8
     
            For i = 1 To 8
    
    
                Set ctlTB = CreateControl(frm.Name, acTextBox, , , , NextColumn, NextRowPos + BlankSpace, ctlWidth, TBoxHeight)
                ctlTB.Name = ctlTBPrefix & y
     
                NextColumn = NextColumn + ctlWidth + BlankSpace
                y = y + 1
                
            Next i
    
    
            NextRowPos = NextRowPos + TBoxHeight + BlankSpace
    
    
            NextColumn = 1000
    
    
        Next j
        
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    82
    This is awesome. Thanks for your code and help!

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Thanks to Moke123 for board layout. I added some code to make alternating colors, and code to name the layout squares in standard chess nomenclature, a1, through h8.

    Here's the DB. Chess-jman-davegri-v01.zip

    The sub can be called from immediate as
    MakeBoard("MyBoard")

    The code below must be in a module, not behind the form. (see attached DB if not clear)

    Code:
    Option Compare Database
    Option Explicit
    
    
    '---------------------------------------------------------------------------------------
    ' Method : MakeBoard
    ' Author : davegri
    ' Date   : 04/14/23
    ' Purpose: Thanks to moke123 for board layout creation.
    ' I added the alternating colors and the code to name the textboxes
    ' with standard chess nomenclature, i.e.; a1 thru h8.
    '---------------------------------------------------------------------------------------
    Sub MakeBoard(fName As String)
        Dim i As Integer, y As Integer, j As Integer
        Dim ctlTBPrefix As String, sAutoName As String
        Dim StartingPosTop As Double
        Dim PosLeft As Double
        Dim NextRowPos As Double
        Dim BlankSpace As Double
        Dim NextColumn As Double
        Dim ctlWidth As Double
        Dim TBoxHeight As Double
        Dim ctlTB As Control
        Dim frm As Form
        If fcnFrmExists(fName) = True Then
            DoCmd.Close acForm, fName
            DoCmd.DeleteObject acForm, fName
        End If
        
        Set frm = CreateForm()
        sAutoName = frm.Name    'this name is automatically assigned by Access
        DoCmd.Restore
        DoCmd.Close acForm, frm.Name, acSaveYes
        DoCmd.Rename fName, acForm, sAutoName       'change the form autoname to desired name
        DoCmd.Restore
        DoCmd.OpenForm fName, acDesign
        
        ctlWidth = 1440
        TBoxHeight = 1440
        StartingPosTop = 1000
        PosLeft = 1000
        BlankSpace = 10
        NextColumn = 1000
        NextRowPos = 1000
        y = 0
        For j = 8 To 1 Step -1      'row
            For i = 1 To 8          'column
                Set ctlTB = CreateControl(fName, acTextBox, , , , NextColumn, NextRowPos + BlankSpace, ctlWidth, TBoxHeight)
                ctlTB.Name = Choose(i, "a", "b", "c", "d", "e", "f", "g", "h") & j
                Select Case j Mod 2
                    Case Is > 0
                        If i Mod 2 > 0 Then
                            ctlTB.BackColor = vbWhite
                        Else
                            ctlTB.BackColor = vbBlack
                        End If
                    Case Is = 0
                        If i Mod 2 > 0 Then
                            ctlTB.BackColor = vbBlack
                        Else
                            ctlTB.BackColor = vbWhite
                        End If
                End Select
                NextColumn = NextColumn + ctlWidth + BlankSpace
                y = y + 1
            Next i
            NextRowPos = NextRowPos + TBoxHeight + BlankSpace
            NextColumn = 1000
        Next j
        DoCmd.Close acForm, fName, acSaveYes
    End Sub
    Public Function fcnFrmExists(sFrmName As String) As Boolean
        Dim frm As Access.AccessObject
        For Each frm In Application.CurrentProject.AllForms
            If sFrmName = frm.Name Then
                fcnFrmExists = True
                Exit For
            End If
        Next frm
    End Function
    Last edited by davegri; 04-14-2023 at 11:43 AM. Reason: clarif for code location

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

Similar Threads

  1. VBA IDE SDI Layout
    By Perceptus in forum Programming
    Replies: 2
    Last Post: 10-05-2015, 09:45 AM
  2. Variable layout
    By GraeagleBill in forum Forms
    Replies: 4
    Last Post: 08-18-2014, 11:12 PM
  3. Layout Format
    By Mrdude1020 in forum Access
    Replies: 14
    Last Post: 07-17-2014, 10:19 AM
  4. Database Layout
    By adams77 in forum Database Design
    Replies: 5
    Last Post: 10-16-2013, 12:57 PM
  5. report layout
    By ippy in forum Reports
    Replies: 0
    Last Post: 12-09-2010, 01:23 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