469,150 Members | 1,951 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,150 developers. It's quick & easy.

Clear fields after inserting records

55
I have a 5-tabbed form that is used to add records in five different tables. The tables are excel-linked. When I press the save button the records goes to different tables but the fields are not cleared. So I want a way to clear the fields after inserting the records. Pls Help!!!
Nov 14 '08 #1
7 5123
MindBender77
234 100+
Your situations is a little unclear but, I'll answer the best i can. The simplest way to accomplish what you ask is to add the following to the OnClick event of your save button:
Expand|Select|Wrap|Line Numbers
  1. Textbox1 = ""  'The name of each control on your form supplying a record.
  2. Textbox2 = ""
  3. etc.
  4.  
OR
Expand|Select|Wrap|Line Numbers
  1. Textbox1 = Null
  2. Textbox2 = Null
  3.  
This could also be done using a loop or by using DoCmd.gotorec,,AcNewRec if the 5 tabbed forms are linked to the 5 tables.

Hope this points you in the right direction,
Bender
Nov 14 '08 #2
Lebbsy
55
Thank you very much for your help. Even though I had to go a bit deeper but I managed to solve it as follows:

Expand|Select|Wrap|Line Numbers
  1. Forms!Computer!TabCtl0.Pages!CPUInfo.Controls!cpu.Text = ""
Nov 19 '08 #3
Lebbsy
55
Well for a minute I thought that worked but going on the backend I realised that putting that code in the OnClick button would make the fields in the table blank as well whereas I want it to save the records in the table and leave the form fields blank then go to next record. So the code is right but where do I put it because its not in the OnClick event?
Nov 19 '08 #4
MindBender77
234 100+
Ok, it seems that all of your forms and there corresponding fields are linked to tables. What you ask could easily been done using DoCmd.

On the OnClick event try using: DoCmd.GoToRec,,AcNewRec.

This should save your record then move to a new record. This will save your records then clear the fields.

HTH,
Bender
Nov 20 '08 #5
Lebbsy
55
I have tried that a long time ago to no help. I have an insert statement to insert values into the different tables and that works successfully. The only problem is after inserting the values the fields do not clear...
Nov 21 '08 #6
MindBender77
234 100+
Ok, lets see if I understand your project.

None of your forms' record sources are link directly to a table and your using an insert query to update several tables via a command button. However, after changing a field (text = "") you also change the data in the table.

From what I understand, it seems like the insert query is running twice or your forms ARE linked to the tables and your running an insert query also. This would produce alot of duplicate entries and/or null records in your tables.

Please provide the code your using with your save records button and the record source of each table. This might shed some light on the problem.

Regards,
Bender
Nov 21 '08 #7
Lebbsy
55
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSav_Click()
  2.  
  3. Dim ctl As Control
  4. Dim stDocName As String
  5.  
  6.     Dim conCars As ADODB.Connection
  7.  
  8.     Set conCars = Application.CurrentProject.Connection
  9.  
  10.  
  11.     conCars.Execute "INSERT INTO Monitor(SerialNo, ManufacturerSerialNo, Make, " & _
  12.                     "Model, DatePurchased, WarrantyPeriod, MonitorSize, " & _
  13.                     "AssignedOfficer) VALUES('', '', '', '', '', '', '', '')"
  14.  
  15.     conCars.Execute "INSERT INTO Officer(Ministry, Department, Division, AssignedOfficer, " & _
  16.                     "OfficeNumber, TelephoneNumber) VALUES('', '', '', " & _
  17.                     "'',  '',  '')"
  18.  
  19.     conCars.Execute "INSERT INTO Printer(SerialNo, Make, Model, DatePurchased, " & _
  20.                     "WarrantyPeriod, ManufacturerSerialNo, AssignedOfficer) VALUES('', '', '', " & _
  21.                     "'', '', '', '')"
  22.  
  23.    conCars.Execute "INSERT INTO Scanner(SerialNo, Make, Model, DatePurchased, " & _
  24.                     "WarrantyPeriod, ManufacturerSerialNo, AssignedOfficer) VALUES('', '', '', " & _
  25.                     "'', '', '', '')"
  26.  
  27.     conCars.Execute "INSERT INTO Processor(SerialNo, ManufacturerSerialNo, Make, Model, " & _
  28.                     "DatePurchased, WarrantyPeriod, CPURAM, Speed, " & _
  29.                     "HDDSize, MouseMake, OperatingSystem, OSProductKey, AssignedOfficer) VALUES('', " & _
  30.                     "'', '', '', '', '',  '',  '',  '',  '', '', '', '')"
  31.  
  32.    'DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
  33. 'DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  34.     conCars.Close
  35.     Set conCars = Nothing
  36.  
  37. End Sub

And the source object of each subform is the respective linked tables:
Processor, Scanner, Printer, Officer and Monitor
Dec 2 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Chumley the Walrus | last post: by
6 posts views Thread by Pushpendra Vats | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.