Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box - Last entered Item as default 1

Status
Not open for further replies.

tstowe

Technical User
Apr 29, 2003
65
US
I have a combo box that will have job names entered.

Each job has multiple contractors that require multiple entries for each job.

What I am wanting is for each new record to default to the last entered job name with the cursor ready at the first field requiring further information.

Your thoughts?

Tony
 
Hi,

many possibilities.
Starting e.g. with creation of a look-up table or even easier save the last entry to the tag of the control, and make it the defaultvalue.

Hope that helps, georgp
 
Thanks for your suggestion(s), however, how do I implement either of your suggestions? Believe me I am a definite newbie on creating access applications.

Tony
 
Hi tstowe,

sorry for answering late.
I am not sure, if you are familiar with VBA, but if you are a little bit serious about Access you should start to learn it. That's the real fun part and it will allow you to do anything you want (with few exceptions). Sooner or later, you will want to do things, you can do only with VBA. So I will explain how to solve your problem in VBA.

Open your form in design view.
If the properties window is not shown, click it (e.g. with F4).
Click your control (e.g. textbox, which should have the defaultvalue) and the properties window will show the NAME of your control (this is the name you should use) in the combobox on top of the properties window. Select the event tab and double click the AFTER UPDATE event. Access will add [EVENT PROCEDURE]. Click the related command button with the three points and you will be in the code window.

The cursor will be between two text lines:

Private Sub YourControlName_AfterUpdate()

End Sub

Add the following text between the lines:

YourControlName.Tag = YourControlName.Value
(this will store your latest text change in this control to the control)

In total it should look like this (in this case the name of the control is "Text0")

Private Sub Text0_AfterUpdate()
Text0.Tag = Text0.Value
End Sub

Go back to your form (e.g. click the access icon) and click the rectangle on the left on the form.
The properties window will show the form properties. Select the event tab and doubleclick the On Current event. Again Access will add [Event Procedure]. Click the three points and you will be in vba again with the cursor in the
Private Sub Form_Current routine.

Enter between the header of the routine and the End Sub following code

If Me.NewRecord Then
Text0.DefaultValue = """" & Text0.Tag & """"
End If
(this will make the latest textchange - incl. entry - your default value)

(my code again assumes that your control name is Text0 - you will have to replace it with your actual name), so that this routine looks finally like:

Private Sub Form_Current()
If Me.NewRecord Then
Text0.DefaultValue = """" & Text0.Tag & """"
End If
End Sub
Make sure that everything is the same, just replace the two "Text0" with your control name.

(Actually,you only need the line Text0.Defaultvalue...., but using the three lines is better practice.)

Go back to your form in design view, and close it. You will be asked to save your work - do so.

Now open your form and it should work as you wanted.

Looks like a lot of work, but once you are used to it, it is a 30 second job - you may just copy it to another control.

Let me know, if it worked... I will be away for a few days.

georgp

georgp
 
georgp,

Your lengthy explanation was to the point and very much correct. I entered the code as you indicated above and it worked perfectly.

Thanks for your time and I hope to have you answer other questions I may have. . . :)

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top