Results 1 to 4 of 4
  1. #1
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    5

    Question Reading a field(s) in a table to build a new record for insertion into a new table


    Objective is to provide a list of all names in a table/record and show the record (LOT) it is from.
    I am trying to help a church manage their cemetery lots and plots. There is one table and each record is a LOT and contains all the information about the 8 PLOTS contained in a LOT. There can be 8 names recorded in any one LOT record. One name for each of the 8 PLOTS in the LOT. To arrive at a list of all the names, in any / every LOT I plan to read each record and write each name and associated LOT number into a new table. I can then create a form listing all names, sorted by name. I did not design the database, I am trying to deal with what I got. There must be many solutions, but I want to do it with VB code. How to open and read the input table SHEET1 and insert multiple records ina table of ALLNAMES, of multiple names found in any one LOT record in SHEET1. I don't expect the reply to answer the whole thing, just the DIM statements to open the the table and insert records into ALLNAMES

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    So you are trying to normalise your data from an excel spreadsheet? So currently you have say

    LOT....PLOT1....PLOT2....PLOT3 etc
    1.......Harry.....Mary.......George etc?

    and what you want is

    LOT...PLOT...OccupiedBy
    1.......1.......Harry
    1.......2.......Mary
    1.......3.......George
    etc

    If so, why do you want to use VBA? Much easier and faster to use SQL.

    In SQL it would be

    Code:
    INSERT INTO newTable (LOT,PLOT, OccupiedBy)
    SELECT LOT, 1, PLOT1 FROM sheet1
    UNION SELECT LOT, 2, PLOT2 FROM sheet1
    UNION SELECT LOT, 3, PLOT3 FROM sheet1
    etc
    in VBA it would be

    Code:
    dim sqlstr as string
    dim db as dao.database
    
    set db=currentdb
    sqlstr="INSERT INTO newTable (LOT,PLOT, OccupiedBy) SELECT LOT, 1, PLOT1 FROM sheet1"
    db.execute sqlstr
    
    sqlstr="INSERT INTO newTable (LOT,PLOT, OccupiedBy) SELECT LOT, 2, PLOT2 FROM sheet1"
    db.execute sqlstr
    
    etc
    both methods will create records for all LOTS - you can remove them afterwards or prevent them from being added by excluding them with criteria

    You want to do it the painfully slow way? (known as RBAR)

    Code:
    dim rs as dao.recordset
    dim db as dao.database
    dim sqlStr as string
    
    sqlStr="SELECT * FROM sheet1"
    set rs=db.openrecordset(sqlstr)
    
    while not rs.eof
        sqlStr="INSERT INTO newTable (LOT,PLOT, OccupiedBy) Values("& rs!LOT & ", 1, '" & rs!PLOT1 & "')"
        db.execute sqlstr
        sqlStr="INSERT INTO newTable (LOT,PLOT, OccupiedBy) Values("& rs!LOT & ", 2, '" & rs!PLOT2 & "')"
        db.execute sqlstr
        etc
    
        rs.movenext
    
    wend

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    There is one table
    As Nancy Reagan said, "Just say NO" to that. That is spreadsheet thinking and does not make for a good relational database design. OK, there are minor exceptions for a flat file but they are rare cases. I wonder if the reason you inherited it is because the design became too much hassle for someone else. VBA is not what you need.

    Off the cuff I'd say you need at least 3 tables (lots, plots, and whatever you call those who are interred) and that would not allow for a table for churches or cemetery owners. Also, what if the plot has one interred above another? How would you manage that with one table? Lots and plots would not be that much different from columbariums, walls and niches I think. While I've never used my columbarium db (it was just an exercise in managing the concept) it sure isn't all packed into one table. Not saying you'd need the same since it was meant to be used in any country and handle sales, but it might need to look a bit closer to this than what you have:
    Click image for larger version. 

Name:	1Columbarium.jpg 
Views:	13 
Size:	98.0 KB 
ID:	51544
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I agree with CJ and Micron that a normalized structure would be the starting point. You may not need all the tables and detail suggested in Micron's data model, but it certainly shows how the various entities are related. You can adapt his model to suit your requirement. It is quite eye-opening to review some cemetery/burial plots/cremation and columbarium software and see some combinations/options.
    Here is a link to 8 Best Cemetery Software it may give you another view of the things involved.

    Here is a link to a thread regarding Database Design of a Burial Register that may help with context and approach.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 11-08-2021, 10:01 AM
  2. Replies: 2
    Last Post: 09-25-2018, 05:33 PM
  3. Replies: 4
    Last Post: 10-30-2017, 11:41 AM
  4. Replies: 1
    Last Post: 06-12-2015, 02:02 PM
  5. Insertion of Year into table already created
    By Tinara in forum Database Design
    Replies: 9
    Last Post: 04-16-2012, 05:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums