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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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
-
Solid color background slows Windows 7 login
by
Alex5723
2 hours, 10 minutes ago -
Windows 11, version 24H2 might not download via Windows Server Updates Services
by
Alex5723
2 hours, 38 minutes ago -
Security fixes for Firefox
by
Susan Bradley
4 hours, 15 minutes ago -
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
4 hours, 1 minute ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
13 hours, 7 minutes ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
4 hours, 6 minutes ago -
Return of the brain dead FF sidebar
by
EricB
10 hours, 8 minutes ago -
windows settings managed by your organization
by
WSDavidO61
14 hours, 13 minutes ago -
Securing Laptop for Trustee Administrattor
by
PeachesP
1 hour, 33 minutes ago -
The local account tax
by
Susan Bradley
5 hours, 48 minutes ago -
Recall is back with KB5055627(OS Build 26100.3915) Preview
by
Alex5723
1 day, 2 hours ago -
Digital TV Antenna Recommendation
by
Win7and10
18 hours, 40 minutes ago -
Server 2019 Domain Controllers broken by updates
by
MP Support
1 day, 14 hours ago -
Google won’t remove 3rd party cookies in Chrome as promised
by
Alex5723
1 day, 15 hours ago -
Microsoft Manager Says macOS Is Better Than Windows 11
by
Alex5723
1 day, 18 hours ago -
Outlook (NEW) Getting really Pushy
by
RetiredGeek
21 hours, 17 minutes ago -
Steps to take before updating to 24H2
by
Susan Bradley
12 hours, 6 minutes ago -
Which Web browser is the most secure for 2025?
by
B. Livingston
1 day, 1 hour ago -
Replacing Skype
by
Peter Deegan
14 hours, 16 minutes ago -
FileOptimizer — Over 90 tools working together to squish your files
by
Deanna McElveen
1 day, 12 hours ago -
Excel Macro — ask for filename to be saved
by
nhsj
10 hours, 13 minutes ago -
Trying to backup Win 10 computer to iCloud
by
SheltieMom
14 hours, 3 minutes ago -
Windows 11 Insider Preview build 26200.5570 released to DEV
by
joep517
3 days, 18 hours ago -
Windows 11 Insider Preview build 26120.3941 (24H2) released to BETA
by
joep517
3 days, 20 hours ago -
Windows 11 Insider Preview Build 22635.5305 (23H2) released to BETA
by
joep517
3 days, 20 hours ago -
No April cumulative update for Win 11 23H2?
by
Peobody
2 days, 8 hours ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
3 days, 21 hours ago -
Boot Sequence for Dell Optiplex 7070 Tower
by
Serge Carniol
4 days, 12 hours ago -
OTT Upgrade Windows 11 to 24H2 on Unsupported Hardware
by
bbearren
6 hours, 11 minutes ago -
Inetpub can be tricked
by
Susan Bradley
2 days, 23 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.