Default values

Scotty0_3

New member
Local time
Today, 13:17
Joined
Aug 29, 2009
Messages
3
I do i create a new record in a form using the values from the previous record as the default values. This is doing my head in please help
 
Are you saying that you want to enter a record, move to a new record, and have the same values for some controls appear in the new record? If so, then in your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record.

Code:
Private Sub YourControlName_AfterUpdate()
   Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
End Sub
On the other hand, if you want to enter a record, close your form, and come back at a later time, open the form and have the same value appear for some controls, that's more complicated, and would have to start with deciding how you would define the "previous" record.
 
you can use a variable for each field... using the DLast Function to get the values of the last records and stor them in theses variables,, then,,, in the befor update event, assign these values to the new record's fields
but using the default value properity has shortcums..!!
i guess.!!
HAMMAM
 
you can use a variable for each field... using the DLast Function to get the values of the last records... HAMMAM

Sorry, HAMMAM, as logical as that sounds, it's simply not true! DLast() is one of those functions whose name has little to do with its actual usage! Here's a quote from Access Help on DFirst() and DLast():

You can use the DFirst and DLast functions to return a random record from a particular field in a table or query when you simply need any value from that field.

As I mentioned earlier, if the OP needs to pull values from the "previous" record, after closing then re-opening the form, he/she will have to first decide exactly how to define what "previous" means, then use something like DLookUp() to retrieve it. If they just want to enter a record, move to a new record, and "pull forward" a value from that first record, the method already given is the way to go.
 
Thankyou for your help
missinglinq
user_offline.gif

AWF VIP
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 2,591
reputation_pos.gif
reputation_pos.gif
reputation_pos.gif



Re: Default values
Are you saying that you want to enter a record, move to a new record, and have the same values for some controls appear in the new record? If so, then in your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record.

Code:
Private Sub YourControlName_AfterUpdate() Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"End Sub


This is what i want but when i try it i keep getting network connection lost ? . I can not understand this as i am not on a network.

As you say there is more than one way to skin a cat. is there any other way of doing this either in a table or form.
or can you see what is wrong with my method

Open form - select field - design - go to control After update - event procedure (type in text below)

Private Sub YourControlName_AfterUpdate()
Me.Works_Order_Number.DefaultValue = """" & Me.Works_Order_Number.Value & """"
End Sub


Am i doing it right

sorry for being a pest and being a bit slow at this
 
Access error messages are often cryptic and frequently don't really relate to the actual error.

The code you're using:
Code:
Private Sub [B]YourControlName[/B]_AfterUpdate()
Me.Works_Order_Number.DefaultValue = """" & Me.Works_Order_Number.Value & """"
End Sub
should read
Code:
Private Sub [B]Works_Order_Number[/B]_AfterUpdate()
Me.Works_Order_Number.DefaultValue = """" & Me.Works_Order_Number.Value & """"
End Sub

You substituted the name of your textbox everywhere except in the sub header.
 
Thank you for taking the time to help me. Is there anything i can do in return please dont hesitate to ask.
 

Users who are viewing this thread

Back
Top Bottom