Option Compare Database
Option Explicit
Private Sub btnOK_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim v As DAO.Field
Dim i As Index
Dim tNamePresent As Boolean
Dim TableExists As Boolean
Dim lngI As Long
Set db = Application.CurrentDb
If IsNull(Me.txtStart) Then
MsgBox "You need a Starting number!"
Exit Sub
End If
If IsNull(Me.txtEnd) Then
MsgBox "You need a Ending number!"
Exit Sub
End If
Const strTableName = "TemptblROEAssignments"
' delete table if already exists
For Each tdf In db.TableDefs
If tdf.Name = strTableName Then
db.TableDefs.Delete strTableName
Exit For
End If
Next
'make table
Set tdf = db.CreateTableDef(strTableName)
Set v = tdf.CreateField("ID", dbLong) 'create field
v.DefaultValue = Me.Combo6 'get its value
tdf.Fields.Append v 'append field to table
Set v = tdf.CreateField("ROE", dbText)
tdf.Fields.Append v
'append table to database
db.TableDefs.Append tdf 'append table to db
Set rst = CurrentDb.OpenRecordset(strTableName, dbOpenDynaset)
For lngI = CLng(Me.txtStart) To CLng(Me.txtEnd)
With rst
.AddNew
.Fields("ROE") = Format(lngI, "00000000") 'the generated number format
.Update
End With
Next lngI
Set rst = Nothing
RefreshDatabaseWindow
DoCmd.RunMacro "mcrAssignROEs" 'runs the update query
End Sub
Private Sub Combo6_AfterUpdate()
Me.Frame21.Visible = True
Me.txtEnd.Visible = True
Me.txtStart.Visible = True
Me.btnOK.Visible = True
End Sub
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
DoCmd.Close
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub
Private Sub Form_Open(Cancel As Integer) 'hiding things until choices are made
Me.Frame16.Visible = False
Me.Frame21.Visible = False
Me.Combo6.Visible = False
Me.txtEnd.Visible = False
Me.txtStart.Visible = False
Me.btnOK.Visible = False
End Sub
Private Sub Frame8_AfterUpdate()
Dim strSQL As String
Dim strSQL2 As String
Dim strSQL3 As String
strSQL = "SELECT ContractorID, CompanyName FROM tblContractors " & _
"ORDER BY [CompanyName]"
strSQL2 = "SELECT StandID, StandAddress FROM tblStands " & _
"ORDER BY [StandAddress]"
strSQL3 = "SELECT TeamID, TeamLeaderlName, TeamLeaderfName FROM tblTeamLeaders " & _
"ORDER BY [TeamLeaderlName]"
Select Case Me.Frame8
Case 1
Me.Combo6.RowSource = strSQL
Case 2
Me.Combo6.RowSource = strSQL2
Case 3
Me.Combo6.RowSource = strSQL3
End Select
Debug.Print Me.Frame8
Me.Frame16.Visible = True
Me.Combo6.Visible = True
End Sub