Inputting Repetitive Data in Form

cordevil95

New Member
Joined
Apr 27, 2006
Messages
33
Hey Guys and Girls,

I have a form where one of the fields has repetitive data input into it. Basically, if the user enters in "TOM" into this field the next 1 to 10 entrys for that same field are also going to be "TOM"

Is there a way to makd the Default Value of the Text Box to be the same as the one directly above it? So when the user gets to this field, we'll call it NAME, they enter in a name then continue and when they get to the NAME box again on the next record set that same name will appear.

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You can use the control's Tag property to achieve this.

In the BeforeUpdate event of the textbox, put this code...
Code:
Private Sub NAME_BeforeUpdate(Cancel As Integer)
    Me.NAME.Tag = Me.NAME
End Sub
In the Current event of the form, put this code...
Code:
Private Sub Form_Current()
    Me.NAME = Me.NAME.Tag
End Sub
If you haven't used code before, here's how to get in --
In Design view, select the Properties of the control, and go to the Events tab
On the BeforeUpdate line, double-click to show Event Procedure and then click the Builder (...) button, which will take you to the code window.
Paste the Me.NAME.Tag = Me.NAME line into the blank row of the sub, so it looks like the sample. Close the window and repeat the process for the form's Current event.

Denis
 
Upvote 0
Thanks!

I'll give that a shot. I use code for alot of things in my database, but I just wasn't sure how to accomplish this one. Thanks again.
 
Upvote 0
OK, that worked great. Only one problem. If I'm going along and for some reason I leave that field blank it gives me a "Run-time error 94: Invalid use of Null"

Any suggestions there?

Thanks again
 
Upvote 0
OK... One more problem. If the user goes back up to a record and changes something it changes the NAME to the last one entered.

Example: Record 200 NAME = "TOM"

User goes to Record 175 to change or update something the NAME for that Record also changes to "TOM" when it should be "SALLY" or something.
 
Upvote 0
You can sort out both of those problems in a couple of ways.
One option...
Code:
Private Sub NAME_BeforeUpdate(Cancel As Integer) 
    If IsNull(Me.NAME) Then
        'do nothing ... keeps the last name in there
    Else
        Me.NAME.Tag = Me.NAME 
    End If
End Sub
In the Current event of the form, put this code... Code:
Code:
Private Sub Form_Current() 
    If IsNull(Me.NAME) Then
        Me.NAME = Me.NAME.Tag 
    Else
        'do nothing ... keeps the last name in there
    End If 
End Sub
Denis
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top