[AccessD] database window appearing when I run code in VBE
Bill Benson
bensonforums at gmail.com
Fri Sep 11 21:55:28 CDT 2015
Ac2013.
Running a macro from the VBA Editor, using F5, I am destroying a database
object (table) and recreating from code. In the process, while running from
the VBE, the VBE window loses focus and the DB window appears.
This wouldn't be an issue at runtime when the UI is all the user would be
seeing, but it is annoying when debugging.
Anyone have a clue what is causing this and if it is avoidable?
Option Compare Database
Option Explicit
Sub CreatePeriods()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim SQL As String
Dim i As Long
Dim rstItems As DAO.Recordset
Set db = CurrentDb
On Error Resume Next
DoCmd.DeleteObject acTable, "Periods"
On Error GoTo 0
DoCmd.CopyObject CurrentDb.Name, "Periods", acTable, "PeriodsTemplate"
SQL = "SELECT Dates.Day, TimeSlots.SlotBegin, TimeSlots.SlotEnd, Dates.ID,
TimeSlots.SlotID"
SQL = SQL & " From TimeSlots, Dates"
SQL = SQL & " ORDER BY Dates.ID, TimeSlots.SlotID"
Set rstItems = db.OpenRecordset(SQL)
With rstItems
While Not .EOF
SQL = "Insert into periods (Dat,TimeSlot,Period) Values ("
SQL = SQL & "#" & .Fields("Day").Value & "#"
SQL = SQL & "," & .Fields("SlotID").Value
SQL = SQL & ",'" & Format(.Fields("SlotBegin").Value, "hh:mm AMPM")
& " - " & Format(.Fields("SlotEnd").Value, "hh:mm AMPM") & "')"
db.Execute SQL
i = i + 1
Debug.Print i & " records inserted"
.MoveNext
Wend
End With
End Sub
More information about the AccessD
mailing list