Novice access to see: How do I repeat the previous record?

Source: Internet
Author: User
Tags exit copy count goto variable
access| Repeat
Novice to see: How to repeat the previous record?



Problem:

How do I repeat the previous record?


There is a form with multiple text boxes and combo boxes on it, because the directory of this information and the next large department of information is the same, can use the copy function of the previous copy of the information to the next corresponding text box and combo box. It is best to make a button, which is a copy button and a paste button.





Method One:

A lot of software has this function ah?


The principle is very simple.

Just add a command BUTTON to it.

Add a record to the code I'm sure we all know it.

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


Let's change it, for example, now there is a text box, of course, you can add code, or simply use controls loop to do.


Private Sub Command16_click ()
On Error GoTo Err_command16_click


Dim strtemp As String
Strtemp=textbox1.value
' principle is very simple, first assign the value of the control to the variable
' Then assign the variable value to the control after adding the record
Docmd.gotorecord, Acnewrec.

Textbox1.value=strtemp
Exit_command16_click:
Exit Sub

Err_command16_click:
MsgBox Err.Description
Resume Exit_command16_click

End Sub


Also CTRL + ' (single quotes) can copy the previous record of the same field contents.





Method Two:

The code that loops with controls is as follows:
Private Sub Autowriterecord ()
' Adaptive
On Error GoTo Err_autowriterecord
Dim D ' Creates a variable
Set D = CreateObject ("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 Then
If Me.Controls (i). Name <> Number Then
' AutoNumber field is not writable, so except that you can use on Error Resume next to ignore
D.add Me.Controls (i). Name, Me.Controls (i). Value
End If
End If
Next I
' principle is very simple, first assign the value of the control to the variable
' Then assign the variable value to the control after adding the record
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_autowriterecord:
MsgBox Err.Description
Resume Exit_autowriterecord

End Sub




Private Sub autowriterecord_1 (strcontrolname as String)
' Human-defined control name
On Error GoTo Err_autowriterecord
Dim D ' Creates 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 very simple, first assign the value of the control to the variable
' Then assign the variable value to the control after adding the record
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.