Sequential Number

slimpickens

New Member
Joined
Feb 17, 2002
Messages
35
I have used this code to get the next available number.

Private sub userform_initialize()
Dim maxval
maxval=WorksheetFunction.Max(Sheets("Sheet1").Range("A:A")) + 1
Userform1.textbox1.text=maxval


I also have a command button on my form which lets me add a record or exit the userform. My problem is that when I add another record my textbox is not recording the next available number. I am guessing that it has something to do with the fact that the form is not being initialized. Can anyone offer any assistance.

Carol
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
On 2002-04-12 11:56, slimpickens wrote:
I have used this code to get the next available number.

Private sub userform_initialize()
Dim maxval
maxval=WorksheetFunction.Max(Sheets("Sheet1").Range("A:A")) + 1
Userform1.textbox1.text=maxval


I also have a command button on my form which lets me add a record or exit the userform. My problem is that when I add another record my textbox is not recording the next available number. I am guessing that it has something to do with the fact that the form is not being initialized. Can anyone offer any assistance.

Carol

Hi Carol,

1. What version of Excel are you using?

2. In your add record event, could you unload the form and then load it again. With screen updating turned off? It might be instantaneous so no one would notice when you re-initialize it.

3. When you click the add record, increase the text box value by 1.

Textbox1 = Textbox1 + 1

might work. Make sure you reference it properly.

HTH,
Jay
 
Upvote 0
Take a look at this code.

MsgBox "One record written to Claim Payments"

response = MsgBox("Do you want to add another record?", _
vbYesNo)

If response = vbYes Then


Polnumber.Text = ""
Claimno.Text = ""
Daypaid.Text = ""
Monthpaid.Text = ""
Yearpaid.Text = ""
Refnumber.Text = ""
Paytype.Text = ""
Payment1.Text = ""
Payment2.Text = ""
Paycode.Text = ""
Paymenttype.Text = ""
Reserve1.Text = ""
Reserve2.Text = ""
Indicator.Text = ""
TextBox1.Text = Commod1.Value & Commod2.Value
TextBox2.Text = Refnumber.Value


Polnumber.SetFocus
Else
For Each w In Application.Workbooks
w.Save
Next w
Application.Quit

End If

End Sub

Where should I put the Unload and Load statements.

Carol
 
Upvote 0
On 2002-04-12 12:23, slimpickens wrote:
Take a look at this code.

MsgBox "One record written to Claim Payments"

response = MsgBox("Do you want to add another record?", _
vbYesNo)

If response = vbYes Then


Polnumber.Text = ""
Claimno.Text = ""
Daypaid.Text = ""
Monthpaid.Text = ""
Yearpaid.Text = ""
Refnumber.Text = ""
Paytype.Text = ""
Payment1.Text = ""
Payment2.Text = ""
Paycode.Text = ""
Paymenttype.Text = ""
Reserve1.Text = ""
Reserve2.Text = ""
Indicator.Text = ""
TextBox1.Text = Commod1.Value & Commod2.Value
TextBox2.Text = Refnumber.Value


Polnumber.SetFocus
Else
For Each w In Application.Workbooks
w.Save
Next w
Application.Quit

End If

End Sub

Where should I put the Unload and Load statements.

Carol

Hi Carol,

After the End If, type in
--------------
Me.Hide
Call Module1.call_again
--------------
Then, in a code module (Module1 in my example above)

---------------
Sub call_again()
Unload UserForm1
UserForm1.Show
End Sub
---------------

This worked for me.

HTH,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,182
Members
448,872
Latest member
lcaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top