Results 1 to 7 of 7
  1. #1
    Poohbear0471 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    78

    Auto-fill form fields from query

    I'm building a database to track alliance members in a multiplayer online game I play. I have two forms to track participation in two different events (Titan and War). One has the player name plus three fields, the other is the player name and two fields. I would like my forms to automatically populate the names of all of my active members (an enforced maximum of 30). I'm currently using combo boxes in datasheet view, so I need to populate each player manually. Suggestions?



    On a side note, I know there's a lot of work to do on it. It kinda grew more than I expected and I missed a lot of best practices, so kindly ignore those. But any other suggestions are welcome.

    Thanks!
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Exactly which table do you want these records in - TitanDailyData?

    You want to create a batch of records for an event?

    INSERT INTO TitanDailyData(TitanDate, Member) SELECT [enter some date], Player FROM Members;

    Why don't you save TitanID instead of date into TitanDailyData? Why aren't you saving MemberID as foreign key instead of Player? TitanID, WarID, and MemberID are defined as primary keys. Primary key should be value saved as foreign key. Relationships should be set on primary and foreign keys.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Poohbear0471 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    78
    Like I said, it grew faster than I was expecting and have a lot to clean up.

    The Insert statement would go in the On Load event, correct?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Well, try it but I think a button on parent form would be better or AfterUpdate of an input control.

    I forgot # delimiters for date field.

    CurrentDb.Execute "INSERT INTO TitanDailyData(TitanDate, Member) SELECT #[enter some date]#, Player FROM Members"

    You understand need to put actual date in place of [enter some date]. The date input can be reference to a form field/control.

    CurrentDb.Execute "INSERT INTO TitanDailyData(TitanDate, Member) SELECT #" & Me.TitanDate & "#, Player FROM Members"

    Need parent record in TitanDaily first. So run code to save TitanDaily record if it is a new record then run the INSERT for dependent records.

    Better have TitanDate and Member set as compound index No Duplicates in table design.


    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Poohbear0471 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    78
    I removed TitanDate from TitanDailyData and set the DailyID as the foreign key and fixed the MemberID issue.

    I have the following code attached to a button (I double checked my updated fields match correctly).

    Private Sub FillRoster_Click()

    CurrentDb.Execute "INSERT INTO TitanDailyData(DailyID, MemberName) SELECT Me.DailyID, MemberName FROM MembersQuery"

    End Sub

    I open a new form (TitanDaily), and populate the parent record so the DailyID autonumber is saved. I click the button to run the code and I get an error message that I'm missing parameters. "Run-Time Error '3061': Too few parameters. Expected 1." I've searched microsofts VBA reference for "Execute" and "CurrentDb.Execute" and I can't find what parameters it's looking for. I have the code pop-up help turned on. It shows Execute(Query as String, [Options]), but I can't find what those options are.

    Help says it could be an unknown field name (mis-spelled, doesn't exist, etc.), but I double and triple checked that.

    Any idea what I did wrong?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Note the concatenation on my example. You are not doing that in your code.

    You need to pull DailyID from the form. This is a variable input. Do not put variables within quote marks. Reference to form control is a variable input.
    Me. is a qualifier alias for the form name the code is behind.

    Should still have compound index to prevent duplicate pairs.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Poohbear0471 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    78
    Thank you! I got it working. I have to refresh the form after I run it to get it to display, but it's working. Thank you SO MUCH!

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

Similar Threads

  1. Auto Fill Fields in a Form using a Combo field
    By jlindquist23 in forum Access
    Replies: 9
    Last Post: 03-14-2019, 10:55 AM
  2. auto fill fields based on another field
    By dbell in forum Forms
    Replies: 18
    Last Post: 05-26-2014, 01:46 PM
  3. Replies: 3
    Last Post: 03-21-2012, 01:43 PM
  4. Auto-Fill text fields in the form
    By sk88 in forum Access
    Replies: 2
    Last Post: 01-10-2012, 08:22 PM
  5. auto fill certain text fields?
    By darklite in forum Forms
    Replies: 4
    Last Post: 07-12-2010, 02:20 PM

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