Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43

    Date textbox for multiple records in table


    I'm trying to figure out how to design a form where the user enters in different textboxes data , that will create new entries in a table , and one date-textbox that will add the date entered in each record created!

    Is there a way?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why do you want to save calculated data? Requires code. Specifics depend on your data structure.

    The date textbox can have a Default Value of Date(). This will insert the current date when a new record is started. Or Now() for date and time.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One way would be to have the default value property of the data entry textbox refer to the textbox where the user entered the date.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Quote Originally Posted by June7 View Post
    Why do you want to save calculated data? Requires code. Specifics depend on your data structure.

    The date textbox can have a Default Value of Date(). This will insert the current date when a new record is started. Or Now() for date and time.
    Yes something like that but with the date entered by the user and not date().

  5. #5
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Quote Originally Posted by pbaldy View Post
    One way would be to have the default value property of the data entry textbox refer to the textbox where the user entered the date.
    I think this might work !
    Have you some suggestions for the form's textboxes that will create each a new record into table?

    should I use INSERT INTO statement?

  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
    I'm not clear on what you're trying to do. The simplest method is to use a form bound to the table, in which case data is automatically going into the table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    supposing you have 3 textboxes:

    txtbox1
    txtbox2
    txtbox3

    the user may enter data to the above textboxes and create 3 different records on a table (on a button click for example)

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The data in the 3 textboxes go to the same field? Why not just have form bound to table, one textbox bound to the field? User makes input to each new record. Voila, records created, data saved, no code! This is the genius of Access - bound forms and controls.
    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.

  9. #9
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Quote Originally Posted by June7 View Post
    The data in the 3 textboxes go to the same field? Why not just have form bound to table, one textbox bound to the field? User makes input to each new record. Voila, records created, data saved, no code! This is the genius of Access - bound forms and controls.
    Because that way there should be a combobox for the user to make a selection for what he enters a value , enter value , enter date and click save button ,repeated 3 times.

    The way I describe I would create 4 textboxes , so the user enters only values and date only one time click save and GO

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You need 4 fields of data saved to 3 records, one field of each record with different value from each textbox of unbound form? Yes, that would require VBA code to run SQL INSERT action.

    Can use AfterUpdate event of each textbox to run INSERT.

    Or use a button Click event with a Loop structure. Give the 3 textboxes names like: Data1, Data2, Data3.

    For i = 1 to 3
    If Not IsNull(Me.Controls("Data" & i)) Then
    CurrentDb.Execute "INSERT INTO tablename (field1, field2, field3, field4) VALUES ('" & Me.Controls("Data" & i) & "', '" & otherdatatextbox1 & "', '" & otherdatatextbox2 & "', #" & datetextbox & "#")
    End If
    Loop

    Note the apostrophe (for text) and # (for date) delimiters, no delimiters for numeric.

    Do you want to prevent the user from accidentally saving another 3 record set of these entries?

    Think bound form with pbaldy's suggestion for Default Value will probably be simpler.
    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.

  11. #11
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Quote Originally Posted by June7 View Post
    You need 4 fields of data saved to 3 records, one field of each record with different value from each textbox of unbound form? Yes, that would require VBA code to run SQL INSERT action.
    I'm sorry for my late reply.
    I have not described the procedure correctly:

    assuming that the following is the form
    datebox=
    txtbox1=
    txtbox2=
    txtbox3=

    after user enters data the table will be :

    tbl1.filed1-tbl1.field2-tbl1.field3
    --------------------------------
    txtbox1- value1 -date
    txbox2- value2 -date
    txtbox3 -value3 -date

    so many thanks for your replies!!

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    txtbox1, txtbox2, txtbox3 feed into field1 for 3 records?

    datebox feeds into field3 for 3 records?

    I don't understand where value1, value2, value3 come from for field2.

    Regardless, comments in my last post still apply.
    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.

  13. #13
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Ok last question I know I'm asking too much here!
    How can I prevent the user to re-enter the same values in the same table?

    I appreciate your help

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    One way maybe set the three fields as a compound key.

    Anything else will require VBA code to search the table for the combination when user attempts to save. If combination found, inform user and don't save. A DLookup is one approach, inside the Loop and the first If Then, like:

    If IsNull(DLookup("ID", "tablename", "field1='" & Me.Controls("Data" & i) & "' AND field2='" & otherdatatextbox1 & "' AND field3='" & otherdatatextbox2 & "' AND datefield=#" & datetextbox & "#") Then
    MsgBox "Data already saved."
    Me.textbox1 = Null
    Me.textbox2 = Null
    Me.textbox3 = Null
    Me.datebox = Null
    Me.otherdatatextbox1 = Null
    Me.otherdatatextbox2 = Null
    Me.textbox1.SetFocus
    Else
    'code to save
    End If
    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.

  15. #15
    atom is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    43
    Well I thank you sir very much!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-13-2011, 11:21 AM
  2. Inserting multiple records into a table
    By New2Access in forum Programming
    Replies: 1
    Last Post: 07-07-2011, 09:18 PM
  3. Referencing multiple records in a table
    By akbigcat86 in forum Programming
    Replies: 14
    Last Post: 07-22-2010, 01:30 PM
  4. Replies: 4
    Last Post: 01-25-2010, 04:14 PM
  5. Report to display multiple records by date.
    By af01waco in forum Reports
    Replies: 1
    Last Post: 03-21-2009, 02:12 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