Results 1 to 8 of 8
  1. #1
    benjammin is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Posts
    60

    Help check my form VBA

    Hi, I'm working on creating a small inventory/calibration database. Up until recently I was able to get away with using bound forms to do my data entry (perhaps much to the chagrin of the pros here). Now I've run into a situation where I want to enter in calibration information and it requires me to write to two tables so I can produce the query/report I want. Here's how I'm doing this:



    Code:
    Private Sub cmdSaveAdd_Click()
    
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    
    Set db = CurrentDb
    Set rst = db.OpenRecordset("tblCalLog", dbOpenDynaset)
        rst.AddNew
            rst!DateTime = txtDateTime
            rst!CheckedBy = txtCheckedBy
            rst!EquipmentID = cboEquipmentName
        rst.Update
        
        Me!txtDateTime = ""
        Me!txtCheckedBy = ""
        Me!cboEquipmentName = ""
    rst.Close
    
    Set rst = db.OpenRecordset("tblCalWL", dbOpenDynaset)
        rst.AddNew
            rst!SiteID = cboSiteName
            rst!LocationID = cboLocationName
            rst!WellID = cboWellName
        rst.Update
        
        Me!cboSiteName = ""
        Me!cboLocationName = ""
        Me!cboWellName = ""
    rst.Close
    
    db.Close
    
    End Sub
    This works but my question is: Is this an acceptable way to write to a table?


    The reason I'm doing this is tblCalLog has general calibration information, just the equipment and date/time it was checked, this is so i can run a report/query to show what instruments will be needing calibration after X months. tblCalWL is the specific table with the calibration information for the well or the instrument, i.e. the actual measurements taken and any associated notes. tblCalLog will hold ALL calibrations and then tables such as tblCalWL will be underneath that holding specific information for each tblCalLog record.

    One more question. When I write to tblCalLog, it creates a new record, how do I pull the ID (autonumber field) that was just created in tblCalLog and write it to tblCalWL so they're related?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I use bound forms at least 75% of the time. Basically I use bound forms unless there's some reason I can't. What's your question? The code looks fine offhand. If the tables are going to get large, you'll want to use dbAppendOnly or this type of thing:


    Set rst = db.OpenRecordset("SELECT * FROM tblCalLog WHERE 1=0", dbOpenDynaset)

    Otherwise you're pulling the entire table, which would be a performance problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    benjammin is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Posts
    60
    If it looks good then all is well. My question now is how do i get it to pull the ID of the record that was created when tblCalLog had the record added and put it into tblCalWL at the same time?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    benjammin is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Posts
    60
    I have a compile error: Invalid or unqualified reference....
    This is after my first table write...
    Code:
    rst.Update    
    .Bookmark = .LastModified
        lngARKey = !CalibrationID

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That user had a With block going, you don't, so for you:

    rst.Bookmark = rst.LastModified
    lngARKey = rst!CalibrationID


    You'd probably want to name the variable something more relevant to you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    benjammin is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Posts
    60
    ohhh yes that would make a difference. Awesome, works great! Thanks for the help.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. How can I check if a Form is open?
    By Gezza in forum Forms
    Replies: 2
    Last Post: 02-07-2012, 06:31 PM
  2. How to check if a form is open.
    By ismith in forum Forms
    Replies: 2
    Last Post: 01-26-2012, 08:10 AM
  3. Replies: 11
    Last Post: 12-28-2011, 04:27 AM
  4. Form Load Check
    By Kapelluschsa in forum Forms
    Replies: 3
    Last Post: 07-06-2011, 07:21 AM
  5. To check or Un-Check all Boxes in a form
    By devcon in forum Forms
    Replies: 7
    Last Post: 05-01-2010, 12:03 AM

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