I have a SQL statement that creates a table and limites the results based on the Manager’s log-on and selection from a listbox. This is done on a button click event. I want a subfrom, datasheet, to be populated with three of the five fields from that table. I tried the refresh mode but that didn’t work. What event should I be looking at instead. Thank you.
Fay
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Populate table from SQL (Access 03)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Populate table from SQL (Access 03)
- This topic has 4 replies, 3 voices, and was last updated 18 years, 4 months ago.
AuthorTopicWSFay Yocum
AskWoody LoungerDecember 27, 2006 at 5:18 pm #438355Viewing 0 reply threadsAuthorReplies-
WSJezza
AskWoody Lounger -
WSFay Yocum
AskWoody LoungerDecember 27, 2006 at 7:15 pm #1044938Nope I forgot the requery. Now I am getting a message saying that the tblProductivity is currently in use. The subform it tied directly to the tblProductivity table. Here is my code. Thank you. Fay
Private Sub cmdProdRoster_Click()
On Error GoTo Err_cmdProdRoster_ClickDim stDocName As String
Dim strSQL As String
Dim strWhere As StringIf Forms!Main!lstDeptP.ItemsSelected.Count = 0 Then
MsgBox “No departments are selected!!”, vbInformation
[Forms]![Main].SetFocus
Exit Sub
End IfFor Each varItm In Forms!Main!lstDeptP.ItemsSelected
strWhere = strWhere & “, ” & Chr(34) & Forms!Main!lstDeptP.ItemData(varItm) & Chr(34)
Next varItm
strWhere = “PerDiem2Unit In (” & Mid(strWhere, 3) & “)”DoCmd.SetWarnings False
‘Creates the base table that Productivity will be moved over to Excel
strSQL = ” SELECT tblLearners.LastName, tblLearners.Nickname, tblLearners.Credential, ” & _
“tblLearnerDepartments.PerDiem2Unit, tblLearners.Inactive INTO tblProductivity ” & _
“FROM qryLimitDepartments INNER JOIN (tblLearners INNER JOIN tblLearnerDepartments ON ” & _
“tblLearners.LearnerID = tblLearnerDepartments.LearnerID) ON ” & _
“qryLimitDepartments.Department = tblLearnerDepartments.PerDiem2Unit ” & _
“WHERE (((tblLearners.Inactive) = 0) AND ” & strWhere & “) ORDER BY tblLearners.LastName, tblLearners.Nickname ”Me.Requery
Me.RefreshExit_cmdProdRoster_Click:
Exit SubErr_cmdProdRoster_Click:
MsgBox Err.Description
Resume Exit_cmdProdRoster_ClickEnd Sub
-
WSJezza
AskWoody LoungerDecember 27, 2006 at 7:31 pm #1044940I have a feeling that as your subform is currently using data from your tblProductivity it is confliscting with the SQL request. For some reason a little part of my brain is calling to make a temporary table of the data in the form of:
CREATE TABLE #tblBears (
BearID int, BearName char(30) )and populate it with the data but I may go be going down the wrong avenue for Access as this is what I would do in a stored procedure in SQL..sorry
-
WSHansV
AskWoody LoungerDecember 28, 2006 at 1:40 pm #1044989As it is now, you only assemble an SQL statement strSQL but never execute it, so I don’t understand where the warning that the table is in use comes from.
Also, you are requerying the main form, not the subform (assuming that cmdProdRoster is on the main form).Instead of executing a make-table query, which will cause conflicts if a (sub)form is bound to the target table, I would execute a delete query to remove all existing records, followed by an append query to add the new records:
‘ Delete existing records
strSQL = “DELETE * FROM Productivity”
DoCmd.RunSQL strSQL
‘ Append new records
strSQL = “INSERT INTO Productivity ( LastName, NickName, Credential, PerDiem2Unit, Inactive ) ” & _
“SELECT tblLearners.LastName, tblLearners.Nickname, tblLearners.Credential, ” & _
“tblLearnerDepartments.PerDiem2Unit, tblLearners.Inactive ” & _
“FROM qryLimitDepartments INNER JOIN (tblLearners INNER JOIN tblLearnerDepartments ON ” & _
“tblLearners.LearnerID = tblLearnerDepartments.LearnerID) ON ” & _
“qryLimitDepartments.Department = tblLearnerDepartments.PerDiem2Unit ” & _
“WHERE tblLearners.Inactive = 0 AND ” & strWhere & ” ORDER BY tblLearners.LastName, tblLearners.Nickname”
DoCmd.RunSQL strSQL
‘ Requery subform
Me.Subformname.RequeryYou must replace Subformname with the name of the subform as a control on the main form. This is not necessarily the same as the name of the subform in the database window. If the name contains spaces or punctuation, put square brackets [ ] around it.
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Sometimes I wonder about these bots
by
Susan Bradley
3 hours, 21 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
5 hours, 20 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
6 hours, 20 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
5 hours, 45 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
2 hours, 15 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
9 hours, 2 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
9 hours, 3 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
2 hours, 56 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
17 hours, 11 minutes ago -
0Patch, where to begin
by
cassel23
11 hours, 13 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day, 6 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
18 hours, 34 minutes ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
1 day, 15 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day, 6 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
17 hours, 28 minutes ago -
Installer program can’t read my registry
by
Peobody
8 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 4 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
1 day, 11 hours ago -
False error message from eMClient
by
WSSebastian42
2 days, 2 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
2 days, 11 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
2 days, 12 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
25 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days, 16 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
1 day, 17 hours ago -
Outdated Laptop
by
jdamkeene
2 days, 21 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
3 days, 3 hours ago -
Another big Microsoft layoff
by
Charlie
3 days, 2 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
4 hours, 57 minutes ago -
May 2025 updates are out
by
Susan Bradley
6 hours, 38 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
3 days, 8 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.