PDA

View Full Version : [SOLVED:] Button to add +1 and button noit to add



hendrikbez
01-11-2016, 01:43 AM
Hi

Using access 2010

I do not know vb at all, but I need help with this, on my form I have a few textbox where I put info into and then it is going to a table.
one one of my textboxes I put in info like "AWER0001".
So when I click on new record it must show the last record of that field in the textbox. So when I press the button for +1 it must change the info in the textbox to the next record AWER0002. This must only happen when I press the button.
Can you help me with this please

jonh
01-11-2016, 04:03 AM
Private Sub Command_Click()

'Uncomment the line below to use the value of the LAST record,
'otherwise it uses the value of the CURRENT record

'DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus1 "txtMyControl" '<-- CHANGE THIS TO YOUR CONTROL

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 , , acNewRec
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

hendrikbez
01-11-2016, 04:40 AM
Jonh

Thank to to try to help me, I did put this in and the toher code, but when I press the button it clears my access form and does nothing after that.
I need it to when I press the button it should show the record with the new number on the form, before I press the save button

Private Sub Command_Click()
DoCmd.GoToRecord , , acLast
NewRec_StrFldPlus1 "Stickernumber"
End Sub.

hendrikbez
01-11-2016, 04:45 AM
Jonh

It is working, thank you for your help

hendrikbez
01-12-2016, 12:57 AM
Jonh

How can I chance it, so that it does not add record yet, only if I press the save button, it must add record, every time I press the plus1 button it adds a new record, with only that info in.