Newcomer to see: How to repeat the last record?
problem:
How to repeat the last record? There is a form, there are multiple text boxes and combo boxes, because the data is the same as the next data, can be used to copy the previous information to the next phase with the copy function. Corresponding text boxes and combo boxs. It is best to make a button type, that is, a copy button and a paste button.
method one:
Do you have this feature in many software? The principle is very simple. Just add a Command button. The code to add records believe that everyone knows.
Private Sub Command16_Click () On Error GoTo Err_Command16_Click DoCmd.GoToRecord,, acNewRec Exit_Command16_Click: Exit Sub Err_Command16_Click: MsgBox Err.Description Resume Exit_Command16_Click End Sub us to change what you can, for example, now have a text box, of course, the actual situation you can Add code, or simply do it with the Controls loop.
Private Sub Command16_Click () On Error GoTo Err_Command16_Click dim strTemp as string strTemp = TextBox1.value 'principle is very simple, first control value is assigned to variable' and then add a record and then the variable value is assigned to the control DoCmd.GoToRecord,, acNewRec TextBox1.Value = start_click: EXIT SUB ERR_COMMAND16_CLICK: MSGBOX Err.Description resume EXIT_COMMAND16_CLICK END SUB EXTRL '(single number) You can copy the content of the same field.
Method Two:
The code with the control cycle is as follows:
Private sub autowritecord () adaptive on error Goto Err_AUTOWRITERECORD DIM D 'Create a variable set d = creteObject ("scripting.dictionary") DIM I as long for i = 0 to me.controls.count - 1 if me.controls i) .ControlType = acTextBox _ Or Me.Controls (i) .ControlType = acComboBox _ Or Me.Controls (i) .ControlType = acListBox _ Or Me.Controls (i) .ControlType = acCheckBox _ Or Me.Controls (i) .ControlType = acOptionButton the IF me.controls (i) .Name <> "Number" The 'Auto Number field is not available, so except, you can ignore D.Add Me.Controls (i) .Name, ME, ME, ME, ME, ME, ME, ME, ME. .Controls (i) .Value End if End if Next i 'principle is simple, first assign the control value to the variable' and then assign the variable value to the control DOCMD.GOTORECORD, ACNewRec Dim K k = D Keys for i = 0 to d.count - 1 me.controls (k (i)). Value = d (k (i)) Next i set d = nothing exit_autowriteRecord: exit sub err_autowritecture index: msgBox err.description resume EXIT_AUTOWRITEREC ORD END SUB
Private Sub AutoWriteRecord_1 (strControlName As String) 'manually define control name On Error GoTo Err_AutoWriteRecord Dim D' create a variable Set D = CreateObject ( "Scripting.Dictionary") Dim strSName () As String strSName = Split (strControlName, ";") DIM I as long for i = 0 to Ubound (strsname) - 1 D.Add StrsName (i), Me.Controls (STRSNAME (i)). Value Next I 'principle is simple, first assign the control value to the variable' After adding the record, the variable value is assigned to the control DOCMD.GOTORECORD,, Acnewrec for i = 0 to Ubound (strsName) - 1 me.controls (strsName (i)). Value = D (strsname (i)) Next I Set D = Nothing Exit_AutoWriteRecord: Exit Sub Err_AutoWriteRecord: MsgBox Err.Description Resume Exit_AutoWriteRecord End Sub test: Private Sub Command16_Click () 'AutoWriteRecord AutoWriteRecord_1 "field 1; field 2; field 4;" End Sub
http://www.access911.net webmaster collection