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
-
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
2 hours, 11 minutes ago -
Turning off OneDrive
by
CWBillow
6 hours, 40 minutes ago -
June 2025 updates are out
by
Susan Bradley
7 minutes ago -
Mozilla shutting Deep Fake Detector
by
Alex5723
16 hours, 58 minutes ago -
Windows-Maintenance-Tool (.bat)
by
Alex5723
2 hours, 20 minutes ago -
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
19 hours, 30 minutes ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
19 hours, 31 minutes ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
19 hours, 29 minutes ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
11 hours, 22 minutes ago -
re-install Windows Security
by
CWBillow
22 hours, 46 minutes ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
1 day, 2 hours ago -
macOS Tahoe 26
by
Alex5723
20 hours, 40 minutes ago -
Migrating from win10 to win11, instructions coming?
by
astro46
8 hours, 45 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
11 hours, 13 minutes ago -
Recommended watching : Mountainhead movie
by
Alex5723
11 hours, 57 minutes ago -
End of support for Windows 10
by
Old enough to know better
11 hours, 53 minutes ago -
What goes on inside an LLM
by
Michael Covington
6 hours, 6 minutes ago -
The risk of remote access
by
Susan Bradley
1 hour, 46 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
18 hours, 9 minutes ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
16 hours, 11 minutes ago -
Supreme Court grants DOGE access to confidential Social Security records
by
Alex5723
2 days ago -
EaseUS Partition Master free 19.6
by
Alex5723
1 day, 1 hour ago -
Microsoft : Edge is better than Chrome
by
Alex5723
2 days, 14 hours ago -
The EU launched DNS4EU
by
Alex5723
3 days, 2 hours ago -
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
2 days, 17 hours ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
3 days, 8 hours ago -
Set default size for pasted photo to word
by
Cyn
3 days, 14 hours ago -
Dedoimedo tries 24H2…
by
Cybertooth
3 days, 2 hours ago -
Windows 11 Insider Preview build 27871 released to Canary
by
joep517
4 days, 13 hours ago -
Windows 11 ad from Campaign Manager in Windows 10
by
Jim McKenna
2 days, 6 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.