hendrikbez
01-14-2016, 12:47 AM
Hi, I did get this code form Jonh (thank you), did some changes on this, it is working for me, but when I want to add 2 buttons to do the same, I get error, if I press the first button, is put info on second textbox.
I am trying to understand this code, but I am not good at this
The first code is working.
Private Sub addnumber_1_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus1 "Stickernumber"
End Sub
Private Function NewRec_StrFldPlus1(ctlname As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord
Me.Controls(ctlname) = Replace(val1, val2, val2 + 1)
End If
End Function
Private Function NumAtEnd(s As String, num As Long) As Boolean
Dim n, i As Integer
For i = Len(s) To 1 Step -1
Select Case Mid(s, i, 1)
Case 0 To 9
n = Mid(s, i, 1) & n
NumAtEnd = True
Case Else: Exit For
End Select
Next
num = n
End Function
Private Sub KeepNumberSame_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus2 "Stickernumber"
End Sub
Private Function NewRec_StrFldPlus2(ctlname As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord , , acNewRec
Me.Controls(ctlname) = Replace(val1, val2, val2 + 0)
End If
End Function
This don't work, my second textbox is only numbers
Private Sub Booknumber_1_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus3 "BookNumber"
End Sub
Private Function NewRec_StrFldPlus3(ctlname1 As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord
Me.Controls(ctlname) = Replace(val1, val2, val2 + 1)
End If
End Function
Private Sub keepBook_0_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus4 "BookNumber"
End Sub
Private Function NewRec_StrFldPlus4(ctlname1 As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord
Me.Controls(ctlname) = Replace(val1, val2, val2 + 0)
End If
End Function
I am trying to understand this code, but I am not good at this
The first code is working.
Private Sub addnumber_1_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus1 "Stickernumber"
End Sub
Private Function NewRec_StrFldPlus1(ctlname As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord
Me.Controls(ctlname) = Replace(val1, val2, val2 + 1)
End If
End Function
Private Function NumAtEnd(s As String, num As Long) As Boolean
Dim n, i As Integer
For i = Len(s) To 1 Step -1
Select Case Mid(s, i, 1)
Case 0 To 9
n = Mid(s, i, 1) & n
NumAtEnd = True
Case Else: Exit For
End Select
Next
num = n
End Function
Private Sub KeepNumberSame_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus2 "Stickernumber"
End Sub
Private Function NewRec_StrFldPlus2(ctlname As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord , , acNewRec
Me.Controls(ctlname) = Replace(val1, val2, val2 + 0)
End If
End Function
This don't work, my second textbox is only numbers
Private Sub Booknumber_1_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus3 "BookNumber"
End Sub
Private Function NewRec_StrFldPlus3(ctlname1 As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord
Me.Controls(ctlname) = Replace(val1, val2, val2 + 1)
End If
End Function
Private Sub keepBook_0_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus4 "BookNumber"
End Sub
Private Function NewRec_StrFldPlus4(ctlname1 As String) As Boolean
On Error Resume Next
Dim val1 As String, val2 As Long
val1 = Me.Controls(ctlname)
If NumAtEnd(val1, val2) Then
'if control value ends in a number, +1 and create a new record
DoCmd.GoToRecord
Me.Controls(ctlname) = Replace(val1, val2, val2 + 0)
End If
End Function