M
MeSteve
I am trying to update a field on a form. My old code:
Me.ProjectNameShort = Trim(Me.ProjectNameShort)
worked in ACC2003, but threw edit, update ... error when used after going to
ACC2007. So I am trying to use a .edit and .update method. This is what I
have so far, but this updates the first record, not the one that is on the
form.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Projects")
'Add date/time stamp for DateUpdated
With rs
.Edit
!DateUpdated = Now()
.Update
End With
ShortNameEmpty:
With rs
'Force a short name if Long name is filled in
If IsNull(Me.ProjectNameLong) = False Then
.Edit
Me.ProjectNameShort = Trim(Me.ProjectNameShort)
If IsNull(Me.ProjectNameShort) Or Len(Me.ProjectNameShort) < 1 Then
'Set ShortName value using input box
ShortName = InputBox("Please enter an abbreviated name in the
Project Short Name")
'Remove leading or trailing spaces
ShortName = Trim(ShortName)
'Set ProjectNameShort to ShortName
Me.ProjectNameShort = ShortName
.Update
End If
'Prevent ShortName from being Null
.Edit
!ProjectNameShort = Trim(Me.ProjectNameShort)
.Update
If IsNull(Me.ProjectNameShort) Or Len(Me.ProjectNameShort) < 1 Then
GoTo ShortNameEmpty
End If
End If
End With
End Sub
It seems me.something = me.somethingElse no longer works?
Me.ProjectNameShort = Trim(Me.ProjectNameShort)
worked in ACC2003, but threw edit, update ... error when used after going to
ACC2007. So I am trying to use a .edit and .update method. This is what I
have so far, but this updates the first record, not the one that is on the
form.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Projects")
'Add date/time stamp for DateUpdated
With rs
.Edit
!DateUpdated = Now()
.Update
End With
ShortNameEmpty:
With rs
'Force a short name if Long name is filled in
If IsNull(Me.ProjectNameLong) = False Then
.Edit
Me.ProjectNameShort = Trim(Me.ProjectNameShort)
If IsNull(Me.ProjectNameShort) Or Len(Me.ProjectNameShort) < 1 Then
'Set ShortName value using input box
ShortName = InputBox("Please enter an abbreviated name in the
Project Short Name")
'Remove leading or trailing spaces
ShortName = Trim(ShortName)
'Set ProjectNameShort to ShortName
Me.ProjectNameShort = ShortName
.Update
End If
'Prevent ShortName from being Null
.Edit
!ProjectNameShort = Trim(Me.ProjectNameShort)
.Update
If IsNull(Me.ProjectNameShort) Or Len(Me.ProjectNameShort) < 1 Then
GoTo ShortNameEmpty
End If
End If
End With
End Sub
It seems me.something = me.somethingElse no longer works?