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