E
Emma
I am trying to set up the next record on the button if it is blank to get the
highest number and put it in the Client ID field. Here's my code which isn't
working:
Private Sub Command116_Click()
On Error GoTo Err_Command116_Click
Dim intNewID As Integer
Dim strSQL As String
Dim strSQL2 As String
On Error GoTo Err_Command116_Click
'See if Client ID exists if not get new one
If ![Tbl Client Information].[Client ID] Then
'Find the current high number and Add 1 to it
intNewID = Nz(DMax("[Client ID]", "[Tbl Client Information]"), 0) + 1
'Write it to the table ASAP to avoid duplicates in a multi user environment
strSQL = "INSERT INTO [Tbl Client Information] ([Client ID]) SELECT " &
intNewID & ";"
CurrentDb.Execute strSQL, dbFailOnError
'strSQL2 = "INSERT INTO [Tbl Client Information] ([Status]) SELECT
Active;"
'CurrentDb.Execute strSQL2, dbFailOnError
'Make the new record the current record
Me.Requery
With Me.RecordsetClone
.FindFirst "[Client ID] = " & intNewID & ""
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Me.Status.Value = "Active"
Me.Combo157.Value = "Canadian"
Me.Children.Value = "0"
Me.Other.Value = "0"
Me.[Family Profile].Value = "0"
Me.[Marital Status].Value = "0"
Me![Intake Coordinator].Value = CurrentUser
End If
DoCmd.GoToRecord , , acNext
Exit_Command116_Click:
Exit Sub
Err_Command116_Click:
MsgBox Err.Description
Resume Exit_Command116_Click
End Sub
highest number and put it in the Client ID field. Here's my code which isn't
working:
Private Sub Command116_Click()
On Error GoTo Err_Command116_Click
Dim intNewID As Integer
Dim strSQL As String
Dim strSQL2 As String
On Error GoTo Err_Command116_Click
'See if Client ID exists if not get new one
If ![Tbl Client Information].[Client ID] Then
'Find the current high number and Add 1 to it
intNewID = Nz(DMax("[Client ID]", "[Tbl Client Information]"), 0) + 1
'Write it to the table ASAP to avoid duplicates in a multi user environment
strSQL = "INSERT INTO [Tbl Client Information] ([Client ID]) SELECT " &
intNewID & ";"
CurrentDb.Execute strSQL, dbFailOnError
'strSQL2 = "INSERT INTO [Tbl Client Information] ([Status]) SELECT
Active;"
'CurrentDb.Execute strSQL2, dbFailOnError
'Make the new record the current record
Me.Requery
With Me.RecordsetClone
.FindFirst "[Client ID] = " & intNewID & ""
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Me.Status.Value = "Active"
Me.Combo157.Value = "Canadian"
Me.Children.Value = "0"
Me.Other.Value = "0"
Me.[Family Profile].Value = "0"
Me.[Marital Status].Value = "0"
Me![Intake Coordinator].Value = CurrentUser
End If
DoCmd.GoToRecord , , acNext
Exit_Command116_Click:
Exit Sub
Err_Command116_Click:
MsgBox Err.Description
Resume Exit_Command116_Click
End Sub