G
Guest
Access Nubie again asking 2nd question:
I have a database with a bunch of clients by State and a bunch of their
information.
Every month I build a mail merge between excel and word to print out a form
with certain client's infomation on it. I have an excel sheet looking to the
database's query, and then after I refresh the excel query (refreshing the
query's query...:]) I hand input the individual internal control number, by
county, for the clients before I run the mail merge.
I decided to build a form in Access to spit out this information at the
touch of a button. Only one problem: I can't figure out how to renumber the
internal control numbers. We get a couple of hundred cases which need to be
numbered. Example:
Fields: [Internal control number to insert] Last Name, First Name, County
Name, Case Number, County Code
1, Earl, Frank, Essex, C000111, 007
2, Kidd, Tasha, Essex, C222222, 007
1, Arius, Gregg, Monmouth County, C111000, 013
1, Black, Jack, Ocean, C151515, 015
2, Doe, John, Ocean, C202020, 015
I absolutly KNOW Access has this capablility otherwise how could business
create new numbers for their clients.
I had theorized that I could query each county's case and then number them
but alas, I can't find a numbering function.
Then I tried to make a table to do it in, but the autonumber function only
works if you specify it at creation.
So I tried to create a table with the autonumber, for each county, and then
ran an update query. This unfortunately updated the original table and not
the new ones. Finally my mentor, before she went on vacation gave me this
and I can't understand how to integrate it in my code:
Option Compare Database
Option Explicit
Dim countyHold As String
Dim counter As Integer
Dim updCtr As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim recs As Double
Private Sub Command3_Click()
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from CurrentMonth55", dbOpenDynaset)
If RecordsetClone.RecordCount > 0 Then
MsgBox " rec count is " & RecordsetClone.RecordCount
recs = RecordsetClone.RecordCount
End If
rst.MoveFirst
'handle first record
counter = 1
[countyRecNum] = counter
countyHold = [County]
DoCmd.GoToRecord , , acNext, 1
'handle subsequent records
Do Until updCtr = recs
updCtr = updCtr + 1
If countyHold = [County] Then
counter = counter + 1
[countyRecNum] = counter
End If
If Not countyHold = [County] Then
counter = 1
[countyRecNum] = counter
End If
If updCtr = recs Then
MsgBox "done"
DoCmd.Close
Exit Sub
End If
countyHold = [County]
DoCmd.GoToRecord , , acNext, 1
Loop
End Sub
Attack of the clones. Can someone simplify this?
I have a database with a bunch of clients by State and a bunch of their
information.
Every month I build a mail merge between excel and word to print out a form
with certain client's infomation on it. I have an excel sheet looking to the
database's query, and then after I refresh the excel query (refreshing the
query's query...:]) I hand input the individual internal control number, by
county, for the clients before I run the mail merge.
I decided to build a form in Access to spit out this information at the
touch of a button. Only one problem: I can't figure out how to renumber the
internal control numbers. We get a couple of hundred cases which need to be
numbered. Example:
Fields: [Internal control number to insert] Last Name, First Name, County
Name, Case Number, County Code
1, Earl, Frank, Essex, C000111, 007
2, Kidd, Tasha, Essex, C222222, 007
1, Arius, Gregg, Monmouth County, C111000, 013
1, Black, Jack, Ocean, C151515, 015
2, Doe, John, Ocean, C202020, 015
I absolutly KNOW Access has this capablility otherwise how could business
create new numbers for their clients.
I had theorized that I could query each county's case and then number them
but alas, I can't find a numbering function.
Then I tried to make a table to do it in, but the autonumber function only
works if you specify it at creation.
So I tried to create a table with the autonumber, for each county, and then
ran an update query. This unfortunately updated the original table and not
the new ones. Finally my mentor, before she went on vacation gave me this
and I can't understand how to integrate it in my code:
Option Compare Database
Option Explicit
Dim countyHold As String
Dim counter As Integer
Dim updCtr As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim recs As Double
Private Sub Command3_Click()
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from CurrentMonth55", dbOpenDynaset)
If RecordsetClone.RecordCount > 0 Then
MsgBox " rec count is " & RecordsetClone.RecordCount
recs = RecordsetClone.RecordCount
End If
rst.MoveFirst
'handle first record
counter = 1
[countyRecNum] = counter
countyHold = [County]
DoCmd.GoToRecord , , acNext, 1
'handle subsequent records
Do Until updCtr = recs
updCtr = updCtr + 1
If countyHold = [County] Then
counter = counter + 1
[countyRecNum] = counter
End If
If Not countyHold = [County] Then
counter = 1
[countyRecNum] = counter
End If
If updCtr = recs Then
MsgBox "done"
DoCmd.Close
Exit Sub
End If
countyHold = [County]
DoCmd.GoToRecord , , acNext, 1
Loop
End Sub
Attack of the clones. Can someone simplify this?