Hi, guys. I've created a Form for Project Logs, that pulls data from a table that has primary key as AutoNumber data type and its field name - "Project #"...In the form, one of the objects is a bound object called "Project #" that pulls the project# from that table. Here is my problem: Say the last project that was added to the form is Project # 50...When I started adding the next project, number 51 shows in the "Project #" field. However, if I changed my mind and did not save that 51st record, the next time I try to add a project the "Project #" field shows 52, instead of 51. The bottom line is, somehow there is an internal counter that increments the the "Project #" as soon as I click "add new record" regardless of weather I save the record or not. So far the only solution I found, is to add a new "Project #" field to the table and delete the old one, but, it is extremely inpractical to do it that way every time. Another solution that I tried was to write ans SQL query in the vba code that would be something like this. To the click event on "add new record bottom" I added the following code:
This code is supposed to find the maximum value for the field "Project #" and add 1 to it, when adding new record to Form. For some reason it does not work and gives me a "mismatch error"
Thank you very mcuh!
Valeriya
Code:
Private Sub Add_Record_Click()
Dim strSQL As String
On Error GoTo Err_Add_Record_Click
DoCmd.GoToRecord , , A_NEWREC
strSQL = "SELECT Max(SupplyChainProjectList." _ &
"[Project" #]) AS [MaxOfProject #]" _ &
"FROM SupplyChainProjectList;"
Me.Project_ = CLng(strSQL)+ 1
Exit_Add_Record_Click:
Exit Sub
Err_Add_Record_Click:
MsgBox Error$
Resume Exit_Add_Record_Click
End Sub
This code is supposed to find the maximum value for the field "Project #" and add 1 to it, when adding new record to Form. For some reason it does not work and gives me a "mismatch error"
Thank you very mcuh!
Valeriya