Auto Numbering in existing numbers

B

BruceM

DoCmd.Close acForm, "FormName"

You would put this after the line to open the report, if your intention is
to close the form as soon as you have it print the report. Otherwise, the
same code could go into any command button, such as a Close button. It
could also go into the report's Close event.

BTW, I will be away from the newsgroup until Monday. Either somebody else
will pick up the thread if needed, or I will check again on Monday.

KyBoy1976 said:
OK, this works, now what type of code do I insert to have the form "close"
when I press the print button. I know it has to be in the print button
code
somewhere, just not sure where to insert it, or what the code is.

BruceM said:
In form design view, click the command button to select it, then click
View
Properties. This opens what is known as the Property Sheet. Click
the
Event tab. You will see, among other things, "On Click". Click the row
(it
may already contain the words [Event Procedure], then click the three
dots.
If it says [Event Procedure] the Visual Basic editor will appear. If
not,
you would choose Code Builder, then OK to open the VB editor.
I think this is what you have already described.
You have a command button called Print_Official_License. It's Click
event
starts with:

Private Sub Print_Official_License_Click()

The On Error line of code is part of the error handling. If there is an
error, the code will shoot down to the Err_Print_Official_License_Click
line
(which is what the OnError line specified). After that is the
declaration
of the variable stDocName, and its definition as "Official License",
which I
assume is the name of the report you wish to print. Replace acNormal
with
acViewPreview, and the report will open in print preview so that you can
view it before deciding to print it. With acNormal, as I recall, it just
prints immediately. Add a comma, then another, the put it the Where
condition as I have written it, except use the relevant field name from
your
own database. If there is a primary key field you can use that in the
expression. Your line of code may end up looking something like:
DoCmd.OpenReport stDocName, acViewPreview, , "LicenseID = " &
Me.LicenseID
Note the double comma. If there is to be a named filter it would go
between
those commas. If there is no filter, the comma is still needed as a
placeholder.
What you are saying here is "Open the report to the record in which the
field LicenseID is the same as LicenseID on this form."

The next bit of code that starts with Private Sub
Print_Business_License_Click() seems to be for another command button
named
Print_Business_License, and is the same except that you are opening the
form
in preview mode (that is, it is displayed on the screen rather than being
printed immediately).

If you have two command buttons, one to print the form and the other to
preview it first, you will need both Click events, one for each button.

You may do well to use some more helpful error handling code. Instead
of:
MsgBox Err.DESCRIPTION

you could have something like:
MsgBox "Error #" & Err.Number & " (" & Err.Description & ") in
Print_Business_License_Click"

KyBoy1976 said:
This makes some sense to me, however, I'm confused as where I insert
the
lines of code. When I go to the Event for the print button function
and
click the "..." to edit i go into visual basic editor. There are many
many
lines of code there, how do I know where to put this line of code you
gave
me?

What is there now:

Option Compare Database

Private Sub Print_Official_License_Click()
On Error GoTo Err_Print_Official_License_Click

Dim stDocName As String

stDocName = "Official License"
DoCmd.OpenReport stDocName, acNormal

Exit_Print_Official_License_Click:
Exit Sub

Err_Print_Official_License_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Print_Official_License_Click

End Sub
Private Sub Print_Business_License_Click()
On Error GoTo Err_Print_Business_License_Click

Dim stDocName As String

stDocName = "Official License"
DoCmd.OpenReport stDocName, acPreview

Exit_Print_Business_License_Click:
Exit Sub

Err_Print_Business_License_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Print_Business_License_Click

End Sub


:

To print a report for just the current record you can use something
like
this in the command button's Click event (FieldID is the name of the
primary
key or other unique field in the Record Source):

Dim strDoc As String
Dim strCriteria As String

strCriteria = "FieldID = " & Me.FieldID
strDoc = "YourReportName"

DoCmd.OpenReport strDoc, acPreview, , strCriteria

The longhand view of that line of code is:
DoCmd.OpenReport "YourReportName", acViewPreview, , "FieldID = " &
Me.FieldID

By defining the variables strDoc and strCriteria you can use those
instead
of the longer expressions they represent.

Note that the above assumes FieldID is a numeric field. If it is a
text
field:
strCriteria = "FieldID = """ & Me.FieldID & """"
Expanded for clarity:
strCriteria = "FieldID = " " " & Me.FieldID & " " " "

All of this assumes that the report is based on a table or query that
includes FieldID as one of its fields.

What I am looking to create is a print button at the bottom of my
form
to
print a report containing some of this just entered information.
However,
I
need it to only print this one individual copy of the report rather
then
printing all 4000+ everytime.

:

Actually, the default value of the text box bound to the
incrementing
field.
To insert the current date you could put =Date() as the Control
Source
of
an
unbound text box. This would be fine if you wish to show the day a
report
was printed. If you wish to store the value you could use the Date
function
to insert today's date into a table field.
It's not clear what you mean by "a function at the bottom of my
form
to
print and open a page to print my report". Do you intend to print
the
form?
What is the page you want to open.
To print a report you can use the command button wizard to get
yourself
headed in the right direction. Open the toolbox, and be sure the
magic
wand
icon is highlighted (click it if not). Click the command button
icon,
draw
a command button on your form, and follow the prompts.
You can also add a command button without using the wizard. In its
Click
event you would have something like:
DoCmd.OpenReport "rptYourReport", acViewPreview

Substitute your report name for rptYourReport. acViewPreview lets
you
look
at the report; otherwise it is just printed (if I recall correctly
what
happens if acViewPreview is left out).

Actually, i'm the biggest dummie in the world. I was trying to
put
this
function in the default value within the "Table" rather then the
default
value of the form that updates the table.

Now I just need to figure out how to insert a code giving the
current
date
and a function at the bottom of my form to print and open a page
to
print
my
report

:

On Thu, 23 Aug 2007 10:44:01 -0700, KyBoy1976

The DMax function is exactly what I want to happen, however
when I
try
to put
the code in for the function in the default value i get a
message
saying
"Unknown function 'DMax' in validation expression or default
value
on
'Business License Table.ACCTID"

so where do you think I went wrong?

This appears to be the very common References bug. Open any
module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.

John W. Vinson [MVP]
 
G

Guest

That did it, everything I need now is done, thank you so much for all your
help!

BruceM said:
DoCmd.Close acForm, "FormName"

You would put this after the line to open the report, if your intention is
to close the form as soon as you have it print the report. Otherwise, the
same code could go into any command button, such as a Close button. It
could also go into the report's Close event.

BTW, I will be away from the newsgroup until Monday. Either somebody else
will pick up the thread if needed, or I will check again on Monday.

KyBoy1976 said:
OK, this works, now what type of code do I insert to have the form "close"
when I press the print button. I know it has to be in the print button
code
somewhere, just not sure where to insert it, or what the code is.

BruceM said:
In form design view, click the command button to select it, then click
View
Properties. This opens what is known as the Property Sheet. Click
the
Event tab. You will see, among other things, "On Click". Click the row
(it
may already contain the words [Event Procedure], then click the three
dots.
If it says [Event Procedure] the Visual Basic editor will appear. If
not,
you would choose Code Builder, then OK to open the VB editor.
I think this is what you have already described.
You have a command button called Print_Official_License. It's Click
event
starts with:

Private Sub Print_Official_License_Click()

The On Error line of code is part of the error handling. If there is an
error, the code will shoot down to the Err_Print_Official_License_Click
line
(which is what the OnError line specified). After that is the
declaration
of the variable stDocName, and its definition as "Official License",
which I
assume is the name of the report you wish to print. Replace acNormal
with
acViewPreview, and the report will open in print preview so that you can
view it before deciding to print it. With acNormal, as I recall, it just
prints immediately. Add a comma, then another, the put it the Where
condition as I have written it, except use the relevant field name from
your
own database. If there is a primary key field you can use that in the
expression. Your line of code may end up looking something like:
DoCmd.OpenReport stDocName, acViewPreview, , "LicenseID = " &
Me.LicenseID
Note the double comma. If there is to be a named filter it would go
between
those commas. If there is no filter, the comma is still needed as a
placeholder.
What you are saying here is "Open the report to the record in which the
field LicenseID is the same as LicenseID on this form."

The next bit of code that starts with Private Sub
Print_Business_License_Click() seems to be for another command button
named
Print_Business_License, and is the same except that you are opening the
form
in preview mode (that is, it is displayed on the screen rather than being
printed immediately).

If you have two command buttons, one to print the form and the other to
preview it first, you will need both Click events, one for each button.

You may do well to use some more helpful error handling code. Instead
of:
MsgBox Err.DESCRIPTION

you could have something like:
MsgBox "Error #" & Err.Number & " (" & Err.Description & ") in
Print_Business_License_Click"

This makes some sense to me, however, I'm confused as where I insert
the
lines of code. When I go to the Event for the print button function
and
click the "..." to edit i go into visual basic editor. There are many
many
lines of code there, how do I know where to put this line of code you
gave
me?

What is there now:

Option Compare Database

Private Sub Print_Official_License_Click()
On Error GoTo Err_Print_Official_License_Click

Dim stDocName As String

stDocName = "Official License"
DoCmd.OpenReport stDocName, acNormal

Exit_Print_Official_License_Click:
Exit Sub

Err_Print_Official_License_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Print_Official_License_Click

End Sub
Private Sub Print_Business_License_Click()
On Error GoTo Err_Print_Business_License_Click

Dim stDocName As String

stDocName = "Official License"
DoCmd.OpenReport stDocName, acPreview

Exit_Print_Business_License_Click:
Exit Sub

Err_Print_Business_License_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Print_Business_License_Click

End Sub


:

To print a report for just the current record you can use something
like
this in the command button's Click event (FieldID is the name of the
primary
key or other unique field in the Record Source):

Dim strDoc As String
Dim strCriteria As String

strCriteria = "FieldID = " & Me.FieldID
strDoc = "YourReportName"

DoCmd.OpenReport strDoc, acPreview, , strCriteria

The longhand view of that line of code is:
DoCmd.OpenReport "YourReportName", acViewPreview, , "FieldID = " &
Me.FieldID

By defining the variables strDoc and strCriteria you can use those
instead
of the longer expressions they represent.

Note that the above assumes FieldID is a numeric field. If it is a
text
field:
strCriteria = "FieldID = """ & Me.FieldID & """"
Expanded for clarity:
strCriteria = "FieldID = " " " & Me.FieldID & " " " "

All of this assumes that the report is based on a table or query that
includes FieldID as one of its fields.

What I am looking to create is a print button at the bottom of my
form
to
print a report containing some of this just entered information.
However,
I
need it to only print this one individual copy of the report rather
then
printing all 4000+ everytime.

:

Actually, the default value of the text box bound to the
incrementing
field.
To insert the current date you could put =Date() as the Control
Source
of
an
unbound text box. This would be fine if you wish to show the day a
report
was printed. If you wish to store the value you could use the Date
function
to insert today's date into a table field.
It's not clear what you mean by "a function at the bottom of my
form
to
print and open a page to print my report". Do you intend to print
the
form?
What is the page you want to open.
To print a report you can use the command button wizard to get
yourself
headed in the right direction. Open the toolbox, and be sure the
magic
wand
icon is highlighted (click it if not). Click the command button
icon,
draw
a command button on your form, and follow the prompts.
You can also add a command button without using the wizard. In its
Click
event you would have something like:
DoCmd.OpenReport "rptYourReport", acViewPreview

Substitute your report name for rptYourReport. acViewPreview lets
you
look
at the report; otherwise it is just printed (if I recall correctly
what
happens if acViewPreview is left out).

Actually, i'm the biggest dummie in the world. I was trying to
put
this
function in the default value within the "Table" rather then the
default
value of the form that updates the table.

Now I just need to figure out how to insert a code giving the
current
date
and a function at the bottom of my form to print and open a page
to
print
my
report

:

On Thu, 23 Aug 2007 10:44:01 -0700, KyBoy1976

The DMax function is exactly what I want to happen, however
when I
try
to put
the code in for the function in the default value i get a
message
saying
"Unknown function 'DMax' in validation expression or default
value
on
'Business License Table.ACCTID"

so where do you think I went wrong?

This appears to be the very common References bug. Open any
module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.

John W. Vinson [MVP]
 
B

BruceM

Glad to help. Good luck with the project.

KyBoy1976 said:
That did it, everything I need now is done, thank you so much for all your
help!

BruceM said:
DoCmd.Close acForm, "FormName"

You would put this after the line to open the report, if your intention
is
to close the form as soon as you have it print the report. Otherwise,
the
same code could go into any command button, such as a Close button. It
could also go into the report's Close event.

BTW, I will be away from the newsgroup until Monday. Either somebody
else
will pick up the thread if needed, or I will check again on Monday.

KyBoy1976 said:
OK, this works, now what type of code do I insert to have the form
"close"
when I press the print button. I know it has to be in the print button
code
somewhere, just not sure where to insert it, or what the code is.

:

In form design view, click the command button to select it, then click
View
Properties. This opens what is known as the Property Sheet. Click
the
Event tab. You will see, among other things, "On Click". Click the
row
(it
may already contain the words [Event Procedure], then click the three
dots.
If it says [Event Procedure] the Visual Basic editor will appear. If
not,
you would choose Code Builder, then OK to open the VB editor.
I think this is what you have already described.
You have a command button called Print_Official_License. It's Click
event
starts with:

Private Sub Print_Official_License_Click()

The On Error line of code is part of the error handling. If there is
an
error, the code will shoot down to the
Err_Print_Official_License_Click
line
(which is what the OnError line specified). After that is the
declaration
of the variable stDocName, and its definition as "Official License",
which I
assume is the name of the report you wish to print. Replace acNormal
with
acViewPreview, and the report will open in print preview so that you
can
view it before deciding to print it. With acNormal, as I recall, it
just
prints immediately. Add a comma, then another, the put it the Where
condition as I have written it, except use the relevant field name
from
your
own database. If there is a primary key field you can use that in the
expression. Your line of code may end up looking something like:
DoCmd.OpenReport stDocName, acViewPreview, , "LicenseID = " &
Me.LicenseID
Note the double comma. If there is to be a named filter it would go
between
those commas. If there is no filter, the comma is still needed as a
placeholder.
What you are saying here is "Open the report to the record in which
the
field LicenseID is the same as LicenseID on this form."

The next bit of code that starts with Private Sub
Print_Business_License_Click() seems to be for another command button
named
Print_Business_License, and is the same except that you are opening
the
form
in preview mode (that is, it is displayed on the screen rather than
being
printed immediately).

If you have two command buttons, one to print the form and the other
to
preview it first, you will need both Click events, one for each
button.

You may do well to use some more helpful error handling code. Instead
of:
MsgBox Err.DESCRIPTION

you could have something like:
MsgBox "Error #" & Err.Number & " (" & Err.Description & ") in
Print_Business_License_Click"

This makes some sense to me, however, I'm confused as where I insert
the
lines of code. When I go to the Event for the print button function
and
click the "..." to edit i go into visual basic editor. There are
many
many
lines of code there, how do I know where to put this line of code
you
gave
me?

What is there now:

Option Compare Database

Private Sub Print_Official_License_Click()
On Error GoTo Err_Print_Official_License_Click

Dim stDocName As String

stDocName = "Official License"
DoCmd.OpenReport stDocName, acNormal

Exit_Print_Official_License_Click:
Exit Sub

Err_Print_Official_License_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Print_Official_License_Click

End Sub
Private Sub Print_Business_License_Click()
On Error GoTo Err_Print_Business_License_Click

Dim stDocName As String

stDocName = "Official License"
DoCmd.OpenReport stDocName, acPreview

Exit_Print_Business_License_Click:
Exit Sub

Err_Print_Business_License_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Print_Business_License_Click

End Sub


:

To print a report for just the current record you can use something
like
this in the command button's Click event (FieldID is the name of
the
primary
key or other unique field in the Record Source):

Dim strDoc As String
Dim strCriteria As String

strCriteria = "FieldID = " & Me.FieldID
strDoc = "YourReportName"

DoCmd.OpenReport strDoc, acPreview, , strCriteria

The longhand view of that line of code is:
DoCmd.OpenReport "YourReportName", acViewPreview, , "FieldID = " &
Me.FieldID

By defining the variables strDoc and strCriteria you can use those
instead
of the longer expressions they represent.

Note that the above assumes FieldID is a numeric field. If it is a
text
field:
strCriteria = "FieldID = """ & Me.FieldID & """"
Expanded for clarity:
strCriteria = "FieldID = " " " & Me.FieldID & " " " "

All of this assumes that the report is based on a table or query
that
includes FieldID as one of its fields.

What I am looking to create is a print button at the bottom of my
form
to
print a report containing some of this just entered information.
However,
I
need it to only print this one individual copy of the report
rather
then
printing all 4000+ everytime.

:

Actually, the default value of the text box bound to the
incrementing
field.
To insert the current date you could put =Date() as the Control
Source
of
an
unbound text box. This would be fine if you wish to show the
day a
report
was printed. If you wish to store the value you could use the
Date
function
to insert today's date into a table field.
It's not clear what you mean by "a function at the bottom of my
form
to
print and open a page to print my report". Do you intend to
print
the
form?
What is the page you want to open.
To print a report you can use the command button wizard to get
yourself
headed in the right direction. Open the toolbox, and be sure
the
magic
wand
icon is highlighted (click it if not). Click the command button
icon,
draw
a command button on your form, and follow the prompts.
You can also add a command button without using the wizard. In
its
Click
event you would have something like:
DoCmd.OpenReport "rptYourReport", acViewPreview

Substitute your report name for rptYourReport. acViewPreview
lets
you
look
at the report; otherwise it is just printed (if I recall
correctly
what
happens if acViewPreview is left out).

message
Actually, i'm the biggest dummie in the world. I was trying
to
put
this
function in the default value within the "Table" rather then
the
default
value of the form that updates the table.

Now I just need to figure out how to insert a code giving the
current
date
and a function at the bottom of my form to print and open a
page
to
print
my
report

:

On Thu, 23 Aug 2007 10:44:01 -0700, KyBoy1976

The DMax function is exactly what I want to happen, however
when I
try
to put
the code in for the function in the default value i get a
message
saying
"Unknown function 'DMax' in validation expression or default
value
on
'Business License Table.ACCTID"

so where do you think I went wrong?

This appears to be the very common References bug. Open any
module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top