473,785 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatically Fill Fields in Subform

2 New Member
Does anyone have a basic example of a script that can automatically fill fields in a subform? Here is the scenario:

I have a main form for a Sample Lot and I have added some side-fields (not bound to any table) that asks basic information: Number of Samples (x), Quantity, Unit of Measure, Location, Tray...I would then like a button that triggers a script to automatically create the Sample Details (subform) that is autonumbered and then creates "x" number of sample details with all of the above fields populated with the values.

Thanks,

Chris
Jul 30 '07 #1
1 2463
cclayton000
2 New Member
I think I figured it out with a little reading. I'm a noob (of course), but found that an Append Query is the direction to go. Here is my append query:

INSERT INTO Samples ( SampleLotID, LocationID, BoxID, BoxSlot, Quantity, UOMID, SampleContainer Number )
SELECT SampleLots.Samp leLotID, Forms!SampleLot s!SL_Location AS Expr3, Forms!SampleLot s!SL_Box AS Expr5, Forms!SampleLot s!SL_BTcnt AS Expr2, Forms!SampleLot s!SL_Quantity AS Expr1, Forms!SampleLot s!SL_UOM AS Expr4, Forms!SampleLot s!SL_concnt AS Expr6
FROM SampleLots
WHERE (((SampleLots.S ampleLotID)=[Forms]![SampleLots]![SampleLotID]));

The Sample Lot form has the unbound fields with a command button to automatically create additional Samples bound to that lot. Here is the button's script:

Private Sub Command31_Click ()

Dim max As Object
Dim cnt As Integer
Dim slotchk As Object
Dim boxslotcnt As String
Dim contcnt As Integer

On Error GoTo Err_Command31_C lick

Me.Refresh

Set max = Forms!SampleLot s!SL_Count
Set slotchk = Forms!SampleLot s!SL_BoxType
boxslotcnt = 0
contcnt = Me![sf_Samples].Form![SampleRowCount]

If max > slotchk Then GoTo Qty_Command_Cli ck

For cnt = 1 To max
boxslotcnt = boxslotcnt + 1
contcnt = contcnt + 1
Me![SL_BTcnt] = boxslotcnt
Me![SL_concnt] = contcnt
DoCmd.OpenQuery "AddSamples ", acViewNormal, acAdd
Next cnt

Me.Refresh

Exit_Command31_ Click:
Exit Sub

Qty_Command_Cli ck:
MsgBox "Quantity greater than Box Type", vbOKOnly, "Entry Error"
Exit Sub

Err_Command31_C lick:
MsgBox Err.Description
Resume Exit_Command31_ Click

End Sub

So, I think I'm good, but I have more testing on the DB to be sure it's stable. I have two questions now for you all.
1. Are there any obvious errors or "better way to do it" in my code?
2. As I was struggling through assigning variables, some required the "Set" command others could just be placed as expressions. Is there any posting that explains why this is the case?

Thanks,

Chris
Aug 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1912
by: Tim | last post by:
Hello, I'm using Access 2000 and I have a main form with a large subform. When tabbing through the fields on the main from, the screen automatically tabs down, as I like, but when I tab into the subform, the sreen does not automatically scroll vertically as I tab to fields off the screen. Is there a way to fix this so the user does not have to move over to the scroll bar? I know that many might say to make the subform so it fits on...
2
2210
by: DP | last post by:
hi, i have created a video rental database system. i have created a customer form, and a film form. i related all the tables, with; tblCustomer has membershipID, which is primary and autonumber, tblFilm has FilmID, which is primary and autonumber, tblFilmRental , which has RentalID, CsutomerID, and FilmID
1
2561
by: Curtis | last post by:
I am having a problem with the coding below that someone was trying to help me with in another website. I have been to several websites and hopefully here I can get it resolved. I inherited this database and issue, and I apologize for a bit lengthy. The coding is located in the Event Procedure on the "On Open" property of the {rptLetter}: Sub cmdPrint_Click() 'Check if no results in any field, if all missing 'inform user and exit...
4
2105
by: froglog | last post by:
I have created a MS access DB to track transport costs for tax purposes. I enter data into a main form that tracks miles traveled by date with a subform . The subform has fields for the date traveled , toll location and the cost of the toll . The date on the subform is copied from the main form. is a combo box that draws its values from in the table, which also has the fields -Toll ID, Toll text, and toll cost). My question is...
13
3551
by: Mary | last post by:
I'll pulling my hair out on this one and would be so appreciative of any help. I am creating a data entry form to enter results of a student survey. There are 40 questions on the survey. The first 7 have to do with respondent information like grade, class and age. I have those in a table with a PK of RespondentId, which is autonumbered. Questions 8-40 all have the same format. For these questions I have a table set up with the...
11
1881
by: Scotter | last post by:
Hi everyone, I'm having an issue with getting my fields to update when i change records. I have a main form and a subform. The main form has "total", "deposit", and "due" text boxes. The subform has the items, and the item total(# of items*price). I currently have an update query that calculates the Item total. And in the form I have an OnUpdate event that takes the (Total price for the order) - (any deposit) = to ammount due. This...
1
1834
by: bbatson | last post by:
Hello, I have two tables that are feeding a form/subform relationship. The first table, called "Tbl_Projects" lists a variety of projects taken on by a department. A second table called "Tbl_Project_Codes" (the "many" in the one-to-many relationship) details various codes that are associated with the projects. For example, a project may be "Marketing Campaign" and the codes may be "Conference Call," "Road Show," and "One-on-one Meeting." ...
18
32689
by: angi35 | last post by:
I've been puzzling over something, and hopefully someone here can help me figure it out. In Access 2000, I have two forms... let's call them formA and formB. Users enter data first into formA. Then in certain circumstances, they need to complete formB. Four of the controls on FormB pull identical information as 4 of the controls on formA. I want to set up a command button on formA that opens formB and automatically populates these 4...
1
2513
by: z.ghulam | last post by:
Hi, I have a subform in a main form. When I create new records in the subform I would like the Subform. to autofill with the MainForm. It sounds quite simple, but ive been bustin my brains trying to get it to work with no success. The LinkChild / Master fields seem to be set up correctly, as only the subform records for that particular Ref are being shown.
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.