Results 1 to 5 of 5
  1. #1
    ringo196 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    3

    Using the current record to store fields into a new table

    What I'm trying to do seems fairly simple, but I'm having trouble making it work.

    I have a form that uses a combo box to search for a specific record, and then pulls up said record. In this case, the record comes from a query which has the fields MemberName, MemberID, Swipes, and Email. The Combo box searches for members by typing up the member name, then the form brings up the data of the member you just looked up.

    What I'm trying to do, is that on button click, I need to store the MemberName and MemberID onto a new table AttendanceT. I've tried several different methods and what ends up happening is I always end up storing the first record of the query, and not what the current record (that you searched for using the combo box, and whose information are displayed on the form currently).

    I have tried Dlookup as well as setting variables to save fields from specific variables such as namestr = rs!MemberName

    Any help would be appreciated, let me know if you need more information.


    Thanks!


    Ringo


    Here's what the form looks like, the MemberID information isn't displayed, but is part of the query that the form pulls data from.
    Click image for larger version. 

Name:	SignIn.png 
Views:	7 
Size:	116.5 KB 
ID:	18155

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Controls used to input search criteria must be UNBOUND. Is the combobox UNBOUND?

    If you want record in AttendanceT, why isn't this form bound to AttendanceT? Then bind combobox to MemberID field and select member from combobox to create attendance record.

    Should not store member name into AttendanceT, only memberID. And I expect you want a date in the record.

    Otherwise, to create record in another table, use:

    CurrentDb.Execute "INSERT INTO AttendanceT(MemberID, AttendDate) VALUES(" & Me.textboxname & ", Date())"
    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
    ringo196 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    3
    Yeah, the combo box is unbound, that part of the form is working perfectly.

    There's 2 tables in the database, MembersT, which has member details such as phone numbers, emails, if they want to be on the listserv etc. And the other one is AttendanceT which was already mentioned. AttendanceT has 5 fields, AttendanceID, AttendType (Beginner lesson, intermediate lesson and social dance), MemberName, MemberID and Date (default value is current date). The two tables will be in a relationship using MemberID. I used a query MemberSearchQ that returns parts of the MembersT and this query is what the combo box uses. (I guess I could just pull the records directly from MembersT also)

    Here's how I've been adding new records to the AttendanceT table so far. I will try your code though and see if it works!

    Dim db As Database
    Dim rs As DAO.Recordset


    Set db = CurrentDb
    Set rs = db.OpenRecordset("AttendanceT")


    rs.AddNew
    rs("AttendType").Value = "Beginner Lesson"
    'rs("MemberName").Value = DLookup(MemberName, MembersT) -> this is the part that doesn't work correctly


    rs.Update

  4. #4
    ringo196 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    3
    Update!

    I tried the INSERT TO code and I was getting syntax errors. I think I got it to work now though, using this code:

    rs.AddNew
    rs("AttendType").Value = "Beginner Lesson"
    rs("MemberName").Value = Me.MemberName
    rs("MemberID").Value = Me.MemberID


    Thanks for the help!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    INSERT INTO

    not

    INSERT TO
    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.

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

Similar Threads

  1. Add Record from Current Form to a Table
    By Smtz in forum Access
    Replies: 1
    Last Post: 08-26-2013, 03:49 PM
  2. Replies: 7
    Last Post: 10-28-2012, 08:04 AM
  3. Replies: 0
    Last Post: 09-25-2012, 06:50 AM
  4. Replies: 1
    Last Post: 04-25-2012, 12:36 PM
  5. Replies: 3
    Last Post: 09-18-2011, 03:46 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