Is there a way to automatically write certain records in a table when a form is open using VB?
![]() |
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 |
-
Write to table on form open. (2000)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Write to table on form open. (2000)
- This topic has 38 replies, 5 voices, and was last updated 20 years, 7 months ago.
Viewing 3 reply threadsAuthorReplies-
WSr3x3
AskWoody Lounger -
WSr3x3
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSbzimmer
AskWoody LoungerNovember 11, 2004 at 7:28 pm #898724I have a subform that is set to continuous. When the form is brought up for the very first time, the subform is empty. When the user inputs data, it is stored to my table. Then the next time the form is opened, a query is run and certain records are displayed. What I want to do is have 7 records already in the subform when it opens the first time. I can’t put them in the subform design becasue everytime I want a new record, it adds those 7 records. I only need these seven to be created the first time.
-
WScharlotte
AskWoody Lounger -
WSbzimmer
AskWoody LoungerNovember 11, 2004 at 7:37 pm #898746On the subform, the user gives the input – job#, ActivityCode, then inputs time in one of 7 textboxes (one for each day of the week) Some boxes will be null or every box can contain info. When this form is opend for the first time, I have 7 job numbers that I want to automatically show up. These are default that every user will use. The others will vary depending on which project they work on each week. So is there a way to create these seven records when the form is opened for the first time, or is there a better way of doing this?
-
WSbzimmer
AskWoody LoungerNovember 11, 2004 at 7:37 pm #898747On the subform, the user gives the input – job#, ActivityCode, then inputs time in one of 7 textboxes (one for each day of the week) Some boxes will be null or every box can contain info. When this form is opend for the first time, I have 7 job numbers that I want to automatically show up. These are default that every user will use. The others will vary depending on which project they work on each week. So is there a way to create these seven records when the form is opened for the first time, or is there a better way of doing this?
-
-
-
WScharlotte
AskWoody Lounger -
WSpatt
AskWoody LoungerNovember 11, 2004 at 7:39 pm #898748 -
WSbzimmer
AskWoody Lounger -
WScharlotte
AskWoody LoungerNovember 11, 2004 at 7:43 pm #898756You have to question requests that you don’t understand, especially if they come from users, who haven’t a clue as to HOW any of this should be done. Find out what the requester is trying to accomplish. Then come back with your questions about how to do it and *whether* to do it that particular way.
-
WSbzimmer
AskWoody Lounger -
WScharlotte
AskWoody LoungerNovember 11, 2004 at 7:57 pm #898772That’s what they want to accomplish, not why they want to do it that way. It’s easy to get the distinction confused because they sound like the same thing, but they really aren’t. Keep in mind that they are often simpler ways to do things. For instance, you could provide 7 buttons with the name of a day on each button and pop up an input box to accept the information for that day when they clicked on it. Then your form could create a record for that day.
-
WScharlotte
AskWoody LoungerNovember 11, 2004 at 7:57 pm #898773That’s what they want to accomplish, not why they want to do it that way. It’s easy to get the distinction confused because they sound like the same thing, but they really aren’t. Keep in mind that they are often simpler ways to do things. For instance, you could provide 7 buttons with the name of a day on each button and pop up an input box to accept the information for that day when they clicked on it. Then your form could create a record for that day.
-
WSpatt
AskWoody Lounger -
WSbzimmer
AskWoody Lounger -
WSpatt
AskWoody LoungerNovember 11, 2004 at 8:23 pm #898795Does this response mean you agree that when a record is written in the main form then the 7 records need to be written in the subform?
You will have to give me more details. Better than that why don’t you send a compacted/zipped version of your database giving us the details of what form you are doing this in.
-
WScharlotte
AskWoody LoungerNovember 12, 2004 at 11:39 pm #899389Additional information is in post 426105, which is now locked to keep the topic together.
-
WSbzimmer
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSbzimmer
AskWoody LoungerNovember 14, 2004 at 6:43 pm #899837Here is my code:
Private Sub btnAddRecord_Click()
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(“tblTime”)
rs.AddNew
rs!fname = “Jane”
rs!lname = “Brown”
rs.Update
Set rs = Nothing
Set dbs = NothingEnd Sub
The compiler highlights dbs as DAO.Database and says “User-defined type not defined”. Any suggestions?
-
WSbzimmer
AskWoody LoungerNovember 14, 2004 at 6:43 pm #899838Here is my code:
Private Sub btnAddRecord_Click()
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(“tblTime”)
rs.AddNew
rs!fname = “Jane”
rs!lname = “Brown”
rs.Update
Set rs = Nothing
Set dbs = NothingEnd Sub
The compiler highlights dbs as DAO.Database and says “User-defined type not defined”. Any suggestions?
-
WSpatt
AskWoody Lounger -
WScharlotte
AskWoody LoungerNovember 14, 2004 at 6:36 pm #899833Building on Pat’s example, which will add one record, try this …
Dim dbs as DAO.Database
Dim rs as DAO.Recordset
Dim intLoop As IntegerSet dbs = CurrentDB
Set rs = dbs.OpenRecordset("your tablename")
For intLoop = 1 to 7
rs.AddNew
rs!yourfieldnam1 = whatever
rs!yourfieldname2 = "text"
..
..
rs.Update
Next intLoop
Set rs = Nothing
Set dbs = Nothing -
WScharlotte
AskWoody LoungerNovember 14, 2004 at 6:36 pm #899834Building on Pat’s example, which will add one record, try this …
Dim dbs as DAO.Database
Dim rs as DAO.Recordset
Dim intLoop As IntegerSet dbs = CurrentDB
Set rs = dbs.OpenRecordset("your tablename")
For intLoop = 1 to 7
rs.AddNew
rs!yourfieldnam1 = whatever
rs!yourfieldname2 = "text"
..
..
rs.Update
Next intLoop
Set rs = Nothing
Set dbs = Nothing -
WSFrancois
AskWoody Lounger -
WSFrancois
AskWoody Lounger -
WSbzimmer
AskWoody Lounger -
WScharlotte
AskWoody LoungerNovember 12, 2004 at 11:39 pm #899390Additional information is in post 426105, which is now locked to keep the topic together.
-
WSpatt
AskWoody LoungerNovember 11, 2004 at 8:23 pm #898796Does this response mean you agree that when a record is written in the main form then the 7 records need to be written in the subform?
You will have to give me more details. Better than that why don’t you send a compacted/zipped version of your database giving us the details of what form you are doing this in.
-
WSbzimmer
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSbzimmer
AskWoody Lounger -
WScharlotte
AskWoody LoungerNovember 11, 2004 at 7:43 pm #898757You have to question requests that you don’t understand, especially if they come from users, who haven’t a clue as to HOW any of this should be done. Find out what the requester is trying to accomplish. Then come back with your questions about how to do it and *whether* to do it that particular way.
-
-
-
WSbzimmer
AskWoody Lounger
-
WSpatt
AskWoody LoungerNovember 11, 2004 at 7:39 pm #898749WSbzimmer
AskWoody LoungerNovember 11, 2004 at 7:28 pm #898725I have a subform that is set to continuous. When the form is brought up for the very first time, the subform is empty. When the user inputs data, it is stored to my table. Then the next time the form is opened, a query is run and certain records are displayed. What I want to do is have 7 records already in the subform when it opens the first time. I can’t put them in the subform design becasue everytime I want a new record, it adds those 7 records. I only need these seven to be created the first time.
WSpatt
AskWoody LoungerViewing 3 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
-
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
3 hours, 48 minutes ago -
Are Macs immune?
by
Susan Bradley
1 hour, 11 minutes ago -
HP Envy and the Function keys
by
CWBillow
6 hours, 53 minutes ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
15 hours, 5 minutes ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
15 hours, 22 minutes ago -
Unable to update to version 22h2
by
04om
2 hours, 4 minutes ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
22 hours, 50 minutes ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
22 hours, 52 minutes ago -
Very Quarrelsome Taskbar!
by
CWBillow
8 hours, 42 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
1 day, 11 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
1 day ago -
Is your battery draining?
by
Susan Bradley
5 hours, 35 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
3 hours, 22 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
1 day, 15 hours ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
23 hours, 46 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
23 hours, 58 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
16 hours, 38 minutes ago -
National scam day
by
Susan Bradley
23 hours, 31 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
19 hours, 40 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
2 days, 16 hours ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 5 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
2 days, 7 hours ago -
AI is good sometimes
by
Susan Bradley
2 days, 23 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
2 days, 13 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
4 days ago -
June KB5060842 update broke DHCP server service
by
Alex5723
3 days, 22 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
4 days, 2 hours ago -
Excessive security alerts
by
WSSebastian42
2 days, 17 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
4 days, 12 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
11 minutes 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.