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, 5 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
-
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
23 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
48 minutes ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
6 hours, 46 minutes ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
6 hours, 50 minutes ago -
KB5060842 Issue (Minor)
by
AC641
11 hours, 23 minutes ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
13 hours, 56 minutes ago -
24H2 may not be offered June updates
by
Susan Bradley
48 seconds ago -
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
1 day, 2 hours ago -
Turning off OneDrive
by
CWBillow
1 day, 6 hours ago -
June 2025 updates are out
by
Susan Bradley
2 hours, 36 minutes ago -
Mozilla shutting Deep Fake Detector
by
Alex5723
1 day, 17 hours ago -
Windows-Maintenance-Tool (.bat)
by
Alex5723
1 day, 2 hours ago -
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
1 day, 19 hours ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
1 day, 19 hours ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
1 day, 19 hours ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
1 day, 11 hours ago -
re-install Windows Security
by
CWBillow
1 day, 23 hours ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
2 days, 2 hours ago -
macOS Tahoe 26
by
Alex5723
1 day, 20 hours ago -
Migrating from win10 to win11, instructions coming?
by
astro46
8 hours, 6 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
1 day, 11 hours ago -
Recommended watching : Mountainhead movie
by
Alex5723
1 day, 12 hours ago -
End of support for Windows 10
by
Old enough to know better
19 hours, 46 minutes ago -
What goes on inside an LLM
by
Michael Covington
1 day, 6 hours ago -
The risk of remote access
by
Susan Bradley
2 hours, 3 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
14 hours, 16 minutes ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
1 day, 16 hours ago -
Supreme Court grants DOGE access to confidential Social Security records
by
Alex5723
3 days, 1 hour ago -
EaseUS Partition Master free 19.6
by
Alex5723
2 days, 1 hour ago -
Microsoft : Edge is better than Chrome
by
Alex5723
3 days, 14 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.