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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to add +1 to record revision number automatically 1

Status
Not open for further replies.

bendixen

Technical User
May 3, 2007
15
0
0
US
This is probably simple, yet I'm not getting it. I am using a form to update records in a table. To prevent duplicate records from being entered, I am requiring a new revision number to be entered when changes are made to the existing records before the new record can be saved. That part works. The part that doesn't work is getting the command button to automatically add +1 to the existing revision number when entering the record. Here is the VBA I'm trying to use. (It amazes me I got this far!) Help please? Thanks.


Private Sub cmd_ReviseRecordButton_Click()
On Error GoTo Err_cmd_ReviseRecordButton_Click

Dim strRevisionVersion As String
strRevisionVersion = ([Revision_Version] = [Revision_Version] + 1)
Me.Revision_Version = strRevisionVersion

DoCmd.GoToRecord , , acNewRec

Exit_cmd_ReviseRecordButton_Click:
Exit Sub

Err_cmd_ReviseRecordButton_Click:
MsgBox Err.Description
Resume Exit_cmd_ReviseRecordButton_Click

End Sub
 
Code:
Private Sub cmd_ReviseRecordButton_Click()
On Error GoTo Err_cmd_ReviseRecordButton_Click

Dim strRevisionVersion As String
strRevisionVersion = [COLOR=red]([Revision_Version] = [Revision_Version] + 1)[/color]
Me.Revision_Version = strRevisionVersion

    DoCmd.GoToRecord , , acNewRec

Exit_cmd_ReviseRecordButton_Click:
    Exit Sub

Err_cmd_ReviseRecordButton_Click:
    MsgBox Err.Description
    Resume Exit_cmd_ReviseRecordButton_Click
    
End Sub
this evaluates as false

try
Code:
[COLOR=Blue]str([Revision_Version] + 1)[/color]
 
Is Revision_Version being stored as a string? Is it a number? If it is a number then use the appropriate definition - Long (or Integer depending on the length of your number). That aside, just a personal preference on error handling - I like to include the error number.

Code:
Private Sub cmd_ReviseRecordButton_Click()
On Error GoTo Err_cmd_ReviseRecordButton_Click
Dim i As Long

    i = Me.Revision_Version + 1
    Me.Revision_Version = i

    DoCmd.GoToRecord , , acNewRec

Exit_cmd_ReviseRecordButton_Click:
    Exit Sub

Err_cmd_ReviseRecordButton_Click:
    MsgBox Err.Number & ": " & Err.Description
    Resume Exit_cmd_ReviseRecordButton_Click
    
End Sub


~Melagan
______
"It's never too late to become what you might have been.
 
or perhaps:
Code:
[blue]   Me.Revision_Version = CStr(Val(Me.Revision_Version) + 1)[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks. The recommendations helped me see my error(s). It's all a learning process, and the posts helped me understand more than I previously did.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top