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, 3 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
-
TotalAV safety warning popup
by
Theodore Nicholson
53 minutes ago -
two pages side by side land scape
by
marc
1 day ago -
Deleting obsolete OneNote notebooks
by
afillat
1 day, 2 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
5 hours, 10 minutes ago -
Security Essentials or Defender?
by
MalcolmP
7 hours, 54 minutes ago -
April 2025 updates out
by
Susan Bradley
25 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
1 hour, 15 minutes ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
10 minutes ago -
Creating an Index in Word 365
by
CWBillow
17 hours, 51 minutes ago -
Coming at Word 365 and Table of Contents
by
CWBillow
9 hours, 20 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
1 day, 21 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
2 days ago -
W11 24H2 – Susan Bradley
by
G Pickerell
2 days, 2 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
2 days ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
1 day, 17 hours ago -
I installed Windows 11 24H2
by
Will Fastie
12 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
2 days, 6 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
1 hour, 4 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
2 days, 14 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
1 day, 22 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
1 day, 22 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
3 days, 7 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
3 days, 15 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
2 days, 18 hours ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
3 days ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
3 days, 10 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
5 days, 2 hours ago -
50 years and counting
by
Susan Bradley
2 days ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
2 days, 3 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
5 days, 13 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.