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?
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?
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.
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.
Yes something like that but with the date entered by the user and not 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?
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.
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)
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.
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
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.
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!!
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.
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
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.
Well I thank you sir very much!