473,939 Members | 9,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help autopopulating rows in subform based on form criteria

11 New Member
Hi All -

I'm using 2002 and consider myself an intermediate Access user but newbie programmer :) I've been tasked with the db project from hell and have been combing through posts for the last week looking for relevant snippets. The problem is that my problem is multi-tiered and although I've seen hints I haven't yet come across anything like this problem. So - without further ado here's the situation.

I've got a db that has 3 tables. Customer, SWO, and CableRecords. Essentially the purpose of the database is to log serial numbers for cables to ensure unauthorized duplication doesn't occur. Unfortunately for me there are some cases where it's allowed so I can't set a hard and fast rule to not allow them, just have to make the user aware that it exists and let them make the determination based on the data.

The part that I'm struggling with is this.... I need a data entry form of some type that would allow the user to select the customer, assembly (both from the customer table) and SWO (from the SWO table) and enter "# of cables to be built". I then need it to prompt for additional information if it's not an existing assembly (perhaps popup form?) and then autopopulate the cable records table incrementally starting at the next available number based on the number entered in "# of cables to be built".

At this point I feel like a zombie - I've been reading anything and everything I can and have seen different references to either using append or insert. I really need some help on this one as I'm definitely in over my head and there's nobody else able to help me here. I have attached a stripped down version of the db. I'm happy to provide additional info on fields, etc but wanted to see if there's anyone out there that's done something similar. I would normally say that I'm sure there is but after the last week I'm just lost :)

Thanks everyone for your help!
Angie
Attached Files
File Type: zip WIPACDB.zip (60.3 KB, 237 views)
Nov 19 '07 #1
28 2436
NeoPa
32,584 Recognized Expert Moderator MVP
I guess you didn't get very far with the class idea yet Angie.

I may be able to help here (I hope so).
Can you explain in real-world terms what your database is for. I was unable to guess what a cable is or an SWO (some sort of Work Order perhaps).
The attached database saves asking a whole heap of questions, but I'd like a better handle on what you're attempting here.
Nov 28 '07 #2
CatrionnaRain
11 New Member
Lol - a cable is literally that - my company produces electrical cables that are used in cool stuff like rockets and tanks :)

Because of that, the Assembly alone isn't unique - it's the Customer/Assembly combination that makes it unique hence the CableID field in tblCustomer is used as the key.
Essentially any action in the database will start with a form that allows the user to select the Customer from a combo box and enter the Assembly into a text box. When they click the command button it searchs via loading a form (frmCableView) that populates based off a pquery and shows the related SWOs (Sales Work Orders) in a list box and has a subform that displays each individual cable ordered by S/N (serial number).

This part all works beautifully and life is good.

The problem is that I need a way for the user to be able to add X number of records automatically based off the Customer & Assembly (from the tblCustomer) and SWO (from tblSWO).

I would like the user to be able to click the SWO from the listbox on the frmCableView and click an 'Add Record' button to pop open a form where she could enter the number of records she'd like to create [Qty Issued] and enter the information that would repeat in each field of tblCableRecords ([Date], [KIT], [RMA], [DWG Rev], [PWO Rev], [AC Rev], [Issued To], [Issued By], [MOrder], [Comments], [Adjustments]). C/N (cable number) is a number that increases incrementally for each SWO and S/N is incremental for each Customer/Assembly. So, when said user enters the pertinent info and hits the 'Create Records' button then it would autopopulate all 3 tables based off the information contained on that form. Additionally it needs to calculate the C/N and S/N and populate them.

I have done lots and lots of reading and I know I need to use the DMAX function for the incremental records. I think I need to use a Do/While loop for the count and I'm fairly certain this has to do with the AddNew using a recordset (or maybe insert record?). But how those things go together is beyond me at this point my brain feels like a pretzel.

To assist I'm going to attempt to attach a new copy of the db as I've made some changes and the forms I referenced above aren't the same as my intial entry.
Attached Files
File Type: zip WIPACDB.zip (92.0 KB, 126 views)
Nov 28 '07 #3
NeoPa
32,584 Recognized Expert Moderator MVP
OK Angie, I'll try to loook at this when I get home from work this evening.
I'm based in England. What time-zone are you in so that I know when I SHOULDn't expect any responses?
Nov 28 '07 #4
CatrionnaRain
11 New Member
i'm in CST US (Arkansas). My workday ends at 2:30 however my account here is keyed to email my personal email so I should be able to reply up until 9pm or so.

Thank you so much for any help you can give me - I'm learning fast but this is still way above my current level.
Nov 28 '07 #5
NeoPa
32,584 Recognized Expert Moderator MVP
I'm sorry I didn't get much time to look at this this evening :(
I'm out tomorrow and Friday evenings, but if you can wait for me I will make some time at the weekend if I don't manage anything before then. It's difficult working on downloaded databases at work, but I'll download the latest version here (@home) now just in case I can make any progress in the mean-time.
Nov 29 '07 #6
NeoPa
32,584 Recognized Expert Moderator MVP
I've had a very quick look and noticed there are a whole bunch of new items. Mostly queries, but a CustomerLU table too. What is that?
I also noticed that the TblCustomer table didn't seem to contain simple customer data (The same Customer is repeated many times). I think the concepts described in Normalisation and Table structures would be well worth looking at. Can you take a look and let me know if you feel that your database fits into this structure please. At first glance it didn't seem to but I can't check it thoroughly to see if I've misunderstood something somewhere. If it doesn't then my first recommendation before any further progress is made would be to make it so. I know from experience how much more difficult it can be when trying to force a non-normalised database to work for you. It also makes the database a bit harder to "read" from an outsider's point of view.
Let me know what you think about this. If changes are required then I can probably help with ideas of how to go about it when I understand better exactly what you're looking for and how your structure should be working.
Nov 29 '07 #7
CatrionnaRain
11 New Member
The CustomerLU table is actually so I can test how the forms work once we get multiple customers in the DB. The data loaded currently is all for the same customer. Part of the problem and the reason why you see repeating data in the Customer table is that the Assembly is simply one type of cable. So many customers can order the same type of cable but the serialization must follow each customer/assembly combination. The other option is to break Assembly out from Customer and have a PK code for Customer that's referenced in Assembly I just didn't do that because it is the combination of the two that make the key. I'm open to learning though - so if I'm looking at it wrong please tell me :D So then your CableID (customer/assembly) can have multiple Sales Work Orders (SWO) which has it's own set of data that is unique and can repeat across cables so that's why it's in its own table. And in that case it's the CableID and SWO that make the ID the PK in that table. When you get to cablerecords the C/Ns follow each SWO set and the S/Ns follow each CableID (customer/assembly).

I hope that was clarifying and not just redundant. It's been hard to get my head around this one because for one thing I'm working with existing data going back 10+ yrs that has been data entered from log books. There's not much hope of filling in missing info since there aren't people from then that remember these kind of details. Also, I had extreme difficulty finding unique identifiers for the data because there are so many variables in how they're handled (ie, initial thought was assembly until I found out that it repeats across customers).

I've already learned a ton in this project and I'm truly enjoying that part but am just a little frustrated at knowing what I want and yet not quite sure how to get there. I would truly appreciate any help you have to offer.

Thank you :)

PS - Assembly is the cable - cable in this case just references a completed cable vs. assembly being a plan. Sort of like Assembly is the recipe and cable is the baked cookie. Hope that helps :)
Nov 29 '07 #8
CatrionnaRain
11 New Member
Ok - so 8 more hours of beating my head against the wall and internet, and books.... has had me make a few more changes. I've now added the cableID field to tblCableRecords since one of the requirements is that S/N is keyed off of the CableID which wasn't previously available. Below is my sad attempt at programming what I'm trying to accomplish. I'm hoping that it will at least illustrate what I'm attempting and not further muddy the waters. At the very least it will explain why my brain feels like a pretzel right now :)

So.... some things I can't get my head around - S/N is incremental based on cableID and C/N is incremental for each SWO. The sql below is supposed to pull out only the records for the selected SWO because the new cables being added will be using that particular one but I still need the S/N to populate off the DMax of the S/N field by CableID without the SWO filter.

Thank you all for your time and consideration of this brain torturing puzzle!
Expand|Select|Wrap|Line Numbers
  1. Private Sub AddCable_Click()
  2. On Error GoTo Err_AddCable_Click
  3.  
  4. Function AddNewCables()
  5.  
  6. Dim db As Database
  7. Dim rs As Recordset
  8. Dim strSQL As String
  9. Dim QtyInput As Integer
  10. Dim i As Integer
  11. Dim intNum() As Integer
  12. Dim NewSN As Integer
  13. Dim NewCN As Integer
  14.  
  15. strSQL = "SELECT TblCableRecords.CableID, TblCableRecords.SWO_ID, TblCableRecords.Date," _
  16.     & " TblCableRecords.[C/N], TblCableRecords.KIT, TblCableRecords.[S/N]," _
  17.     & " TblCableRecords.RMA, TblCableRecords.[R&D], TblCableRecords.[DWG Rev]," _
  18.     & " TblCableRecords.[PWO Rev], TblCableRecords.[AC Rev], TblCableRecords.[Issued To]," _
  19.     & " TblCableRecords.[Issued By], TblCableRecords.[Qty Issued], TblCableRecords.MOrder," _
  20.     & " TblCableRecords.Comments, TblCableRecords.Adjustments, TblCableRecords.PK1" _
  21.     & " FROM TblCableRecords" _
  22.     & " WHERE TblCableRecords.CableID = [Forms]![frmAddRecord]![CableID] " _
  23.     & " And TblCableRecords.SWO_ID = [Forms]![frmAddRecord]![SWO_ID]"
  24.  
  25. QtyInput = [Forms]![frmAddRecord]![QtyInput].Value
  26.  
  27. ReDim intNum(1 To QtyInput)
  28.  
  29. Set db = CurrentDb() ' Open pointer to current database
  30.   Set rs = db.OpenRecordset(strSQL) ' Create recordset based on SQL
  31.  
  32.   For i = 1 To QtyInput
  33.     Do While Not rs.EOF
  34.  
  35.     NewSN = DMax("S/N", "tblCableRecords") + i
  36.  
  37.         With TblCableRecords
  38.             .AddNew
  39.             ![Date] = [Forms]![frmAddRecord]![Date].Value
  40.             ![DWG Rev] = [Forms]![frmAddRecord]![DWGRev].Value
  41.             ![PWO Rev] = [Forms]![frmAddRecord]![PWORev].Value
  42.             ![AC Rev] = [Forms]![frmAddRecord]![ACRev].Value
  43.             ![Issued To] = [Forms]![frmAddRecord]![IssuedTo].Value
  44.             ![Issued By] = [Forms]![frmAddRecord]![IssuedBy].Value
  45.             ![Qty Issued] = [Forms]![frmAddRecord]![QtyInput].Value
  46.             ![MOrder] = [Forms]![frmAddRecord]![MOrder].Value
  47.             ![Comments] = [Forms]![frmAddRecord]![Comments].Value
  48.             ![KIT] = [Forms]![frmAddRecord]![KIT].Value
  49.             ![RMA] = [Forms]![frmAddRecord]![RMA].Value
  50.             ![S/N] = [NewSN]
  51.             ![RMA] = [Forms]![frmAddRecord]![RMA].Value
  52.             .Update
  53.         End With
  54.     Loop
  55.     Next i
  56.  
  57.     For i = 1 To QtyInput
  58.         Debug.Print "Serial Numbers " & NewSN & " - "; intNum(NewSN)
  59.     Next i
  60.  
  61.     rs.Close
  62.  
  63. Set rs = Nothing
  64. Set db = Nothing
  65.  
  66. End Function
  67.  
  68. Exit_AddCable_Click:
  69.     Exit Function
  70.  
  71. Err_AddCable_Click:
  72.     MsgBox Err.Description
  73.     Resume Exit_AddCable_Click
  74.  
  75. End Function
Nov 29 '07 #9
CatrionnaRain
11 New Member
Sorry - trying to put the tags in now. I've made some more changes since the last set that I _think_ are closer to correct.

Expand|Select|Wrap|Line Numbers
  1. Private Sub AddCable_Click()
  2. On Error GoTo Err_AddCable_Click
  3.  
  4. Function AddNewCables()
  5.  
  6. Dim db As Database
  7. Dim rs As Recordset
  8. Dim strSQL As String
  9. Dim QtyInput As Integer
  10. Dim i As Integer
  11. Dim intNum() As Integer
  12. Dim NewSN As Integer
  13. Dim NewCN As Integer
  14. Dim FstSN As Integer
  15. Dim LstSN As Integer
  16.  
  17. strSQL = "SELECT TblCableRecords.CableID, TblCableRecords.SWO_ID, TblCableRecords.Date," _
  18.     & " TblCableRecords.[C/N], TblCableRecords.KIT, TblCableRecords.[S/N]," _
  19.     & " TblCableRecords.RMA, TblCableRecords.[R&D], TblCableRecords.[DWG Rev]," _
  20.     & " TblCableRecords.[PWO Rev], TblCableRecords.[AC Rev], TblCableRecords.[Issued To]," _
  21.     & " TblCableRecords.[Issued By], TblCableRecords.[Qty Issued], TblCableRecords.MOrder," _
  22.     & " TblCableRecords.Comments, TblCableRecords.Adjustments, TblCableRecords.PK1" _
  23.     & " FROM TblCableRecords" _
  24.     & " WHERE TblCableRecords.CableID = [Forms]![frmAddRecord]![CableID]"
  25.  
  26. QtyInput = [Forms]![frmAddRecord]![QtyInput].Value
  27.  
  28. FstSN = DMax("S/N", "tblCableRecords") + 1
  29.  
  30. LstSN = DMax("S/N", "tblCableRecords") + QtyInput
  31.  
  32. ReDim intNum(1 To QtyInput)
  33.  
  34. Set db = CurrentDb() ' Open pointer to current database
  35.   Set rs = db.OpenRecordset(strSQL) ' Create recordset based on SQL
  36.  
  37.   For i = 1 To QtyInput
  38.     Do While Not rs.EOF
  39.  
  40.     NewSN = DMax("S/N", "tblCableRecords") + i
  41.  
  42.     CableSN = DMax("C/N", "tblCableRecords", "SWO_ID =" & Me.SWO_ID) + 1
  43.  
  44.         With rs
  45.             .AddNew
  46.             ![Date] = [Forms]![frmAddRecord]![Date].Value
  47.             ![DWG Rev] = [Forms]![frmAddRecord]![DWGRev].Value
  48.             ![PWO Rev] = [Forms]![frmAddRecord]![PWORev].Value
  49.             ![AC Rev] = [Forms]![frmAddRecord]![ACRev].Value
  50.             ![Issued To] = [Forms]![frmAddRecord]![IssuedTo].Value
  51.             ![Issued By] = [Forms]![frmAddRecord]![IssuedBy].Value
  52.             ![Qty Issued] = [Forms]![frmAddRecord]![QtyInput].Value
  53.             ![MOrder] = [Forms]![frmAddRecord]![MOrder].Value
  54.             ![Comments] = [Forms]![frmAddRecord]![Comments].Value
  55.             ![KIT] = [Forms]![frmAddRecord]![KIT].Value
  56.             ![RMA] = [Forms]![frmAddRecord]![RMA].Value
  57.             ![S/N] = [NewSN]
  58.             ![RMA] = [Forms]![frmAddRecord]![RMA].Value
  59.             ![SWO_ID] = [Forms]![frmAddRecord]![cboSWO].Value
  60.             ![CableID] = [Forms]![frmAddRecord]![CableID].Value
  61.             ![S/N] = NewSN
  62.             .Update
  63.         End With
  64.     Loop
  65.     Next i
  66.  
  67.     Debug.Print "Serial Numbers " & FstSN & " - " & LstSN & ""
  68.  
  69.     rs.Close
  70.  
  71. Set rs = Nothing
  72. Set db = Nothing
  73.  
  74. End Function
  75.  
  76. Exit_AddCable_Click:
  77.     Exit Function
  78.  
  79. Err_AddCable_Click:
  80.     MsgBox Err.Description
  81.     Resume Exit_AddCable_Click
  82.  
  83. End Function
  84.  
Nov 30 '07 #10

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

Similar topics

5
4955
by: M Wells | last post by:
Hi All, Is it possible to use form criteria in a query / view in an Access 2003 ADP with SQL Server as the backend? ie something like: select * from mytable where recid = forms!! I'm trying to do something like this as the basis for a subform but I
3
2986
by: jburris | last post by:
I have been through enough of these threads to think that this should be an easy fix... but, are there circumstances in which the following code syntax does not work? =!!.Form! (this is out of the Access bible) Specifically, I am adapting the Orders database from the Access templates for my use. I deleted the payments table and am recording them as a field in the Order Details table so that payment is directly tied to each product...
2
1852
by: mnms | last post by:
Hi, I'm trying to create an "overview" form. And I haven't been able to figure out how to get Access to do what I want yet. Basicly what I want, is to populate a subform based on a field selection. In other words, I have several fields like colour, shape, location etc. on my Main form. Now I want to add a subform to my unbound mainform, showing what I have in a table, depending on what is selected in the fields. So if I choose red,...
8
5188
by: NJonge01 | last post by:
Great thanks to all the helpful responses I've read! Recently using MS Access after a lengthy (7-10 years) away from the tool. I apologize for posting a question that for all intents & purposes appears to have been answered several times. Unfortunately, I've tried nearly a dozen approaches that seem to work for others on this board with similar (nearly identical in some cases) problems. I would like to navigate through records on a subform...
13
4724
by: shreyansghia | last post by:
Hello , I am using MS Access 2007. Now if i ve a subform based on a table, filtering the subform is extremely easy . I only ve to click the relevant column head on the subform and check/uncheck the required records (clicking on the column head would yeild a drop down list). However , since my subform is based on a query , i cannot avail the filter option using the above method. I get the error no 3075. Can somebody please help me...
9
4725
by: Patrick A | last post by:
All, I've got a continuous form with one field on it, with a comob
1
2694
by: daleshei | last post by:
I have a combo box with list all the queries I have on my database: Form is called: frm_qry_slct Combo box (Unbound): Combo23 RowSourceType: Table/Query RowSoource:SELECT FROM MSysObjects WHERE =5 And Like "qry_#*" ORDER BY ; Then my SubForm
2
2746
by: csolomon | last post by:
Happy Hump Day! I was wondering if it would be possible to some how resize my subform based on the number of records it holds. I have a subform that I populate via a non-updatable query. It just shows the user what he/she has ordered. Based on this information, I would like for the user to just be able to view the information with out having to scroll. can this be done? Thanks
2
3526
by: dbdb | last post by:
Hai, need a help please. i have a form to view the query subform 1. form name : form1 2. query subform name : subform1 3. textbox name : txtclass1 4. command button name : cmd1 i want to view my query based on the value in the textbox. the field in my query are : noreg, class, M2A, M2E, M2M
12
5079
by: kashif73 | last post by:
Hi, I have a subform (datasheet view) on my Mainform, where a user can enter information. I need help on how to display the required number of rows in my subform based on the number selected in the dropdown box on my mainform. Please see the attached GIF. for example if a user selects 5 from the dropdown then automatcially the subform below should display 5 rows for entering data, with a default value of "UNKNOWN" in each column. many...
0
10134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9963
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
11524
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11291
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
10659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9858
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...
0
6076
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...
2
4447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3501
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.