10. juni 2002 - 19:47Der er
13 kommentarer og 1 løsning
Autofill last value from the same field
Does anyone know how can I set a field's default value in table properties or in form properties so that while entering new records it retrieves the value from the last record? But it should be editable, that is, even though I gets the value from the last record but can enter a new value, if required. Please help me!!!! Thanks. SoloPOLO!
On the forms OnCurrent-event, you place this code:
Private Sub Form_Current() Dim rs As DAO.Recordset If Me.NewRecord Then Set rs = Me.RecordsetClone rs.MoveLast Me![YourField].DefaultValue = "'" & rs![YourField] & "'" rs.Close End If End Sub
If you do then put this code on the forms oncurrent event
Private Sub Form_Current() Dim tempvalue As String
If Me.NewRecord = True Then ' get last value tempvalue = DLookup("[yourtextfieldinthetable]", "yourtabelname", "[theidfield] =" & DMax("[theidfield]", "yourtabelname")) Me.txtfieldname.Value = tempvalue Else End If
If "the last value" means the one you just entered in the previous record you don't need to look it up in any table. All you have to do is save it as a new default value.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.