I´m missing something big

L

Lasse T

Hi all !!

I hope someone are willing to help me explain something.

I have been playing around with Access for some time but when it comes to
VBA i am a total newbie. I get around by searching the web and Usenet when I
get stuck. Now I´m stuck again and I´m beginning to understand that I must
be missing something big when it comes to coding. I can figure out how to
add code to an objects events, for instant Click event of a button. or close
event of a form. When searching around I´m starting to see things like:
Place this code in your report module och place this code in the subform
control. What is this? Where are the report module? What is the subform
control?

I have an example. This code can solve my problem but I don´t know where to
place it. It is a quote from Jeff North:
you can place the following code in your report module
Private Sub Report1_NoData(Cancel as Integer)
MsgBox "Sorry there is no data to print"
Cancel = True
End Sub
This simply tells the user that its no going to print anything (atleast the
button they clicked worked) and then closes the report (Cancel = True). If you
did not include this line then the report would still continue to process
Just a thought

My problem are similar to this. I have a form with three list boxes. I´m
marking one post from every list box and then klick a "search" button that
opens a new form based on a query. If the query are without result i do not
want the new form to open. Instead I want a message saying that there is no
data. I just can not figure out where to put the code.
If someone can point me in the right direction I would be very thankful.

Lasse T
-------------
 
C

Cheryl Fischer

Lasse,

So, open your Report in Design View, then:

1. Press ALT-Enter to open the Property Sheet for the report.

2. You will see another form with a ComboBox at the top which says
"Report".
Leave that one alone. Below the ComboBox is a set of Tabs. Click the one
that says "Events".

3. In the grid below, locate the row labeled, On No Data. It should be
blank. Click anywhere in the white space to the right of the label and you
will see a downward-pointing arrow appear, indicating that this is also a
ComboBox. Click the arrow and select "Event Procedure".

4. Then, notice that there is an ellipsis or three little dots (...) to the
right of the ComboBox. Click the ellipsis and you will open a code window.
You will see that Access has given you a space for entering some code in
this event - it will look something like the following:

Private Sub Report_NoData(Cancel As Integer)

End Sub

5. After the "Private Sub Report_NoData(Cancel As Integer)" line,
insert the code that Jeff provided:

Save and close the module.

hth,
 
L

Lasse T

Ok. Thank you. Your aswer tells me that I was wrong. I´m not missing
anything. This is the way I always thought is should be done. You always
enter code in somethings event. I thought there was someoteher way that I
missed. My next problem I have to figure out myself I think. I´m using a
swedish Access and I cannot find any event that means On No Data. I should
be Vid Ingen Data or something like that in swedish. Perheaps someone from
sweden reads this.

Thank you very much for helping me straiten this out.

Lasse T
--------------

Cheryl Fischer said:
Lasse,

So, open your Report in Design View, then:

1. Press ALT-Enter to open the Property Sheet for the report.

2. You will see another form with a ComboBox at the top which says
"Report".
Leave that one alone. Below the ComboBox is a set of Tabs. Click the one
that says "Events".

3. In the grid below, locate the row labeled, On No Data. It should be
blank. Click anywhere in the white space to the right of the label and you
will see a downward-pointing arrow appear, indicating that this is also a
ComboBox. Click the arrow and select "Event Procedure".

4. Then, notice that there is an ellipsis or three little dots (...) to the
right of the ComboBox. Click the ellipsis and you will open a code window.
You will see that Access has given you a space for entering some code in
this event - it will look something like the following:

Private Sub Report_NoData(Cancel As Integer)

End Sub

5. After the "Private Sub Report_NoData(Cancel As Integer)" line,
insert the code that Jeff provided:

Save and close the module.

hth,
--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Lasse T said:
Hi all !!

I hope someone are willing to help me explain something.

I have been playing around with Access for some time but when it comes to
VBA i am a total newbie. I get around by searching the web and Usenet
when
 
L

Lasse T

Oops. I was wrong. I found On No Data in the report propertys. The problem
is that I´m trying to do this with a form.

Lasse
-------------


Lasse T said:
Ok. Thank you. Your aswer tells me that I was wrong. I´m not missing
anything. This is the way I always thought is should be done. You always
enter code in somethings event. I thought there was someoteher way that I
missed. My next problem I have to figure out myself I think. I´m using a
swedish Access and I cannot find any event that means On No Data. I should
be Vid Ingen Data or something like that in swedish. Perheaps someone from
sweden reads this.

Thank you very much for helping me straiten this out.

Lasse T
--------------
 
C

Cheryl Fischer

Perhaps this will help ...

When I open a report (Access 2002) in design view and look at the Events, I
see that there are 7 events listed, in order as follows:

On Open
On Close
On Activate
On DeActivate
On No Data
On Page
On Error

While there may be language differences, I would think that the events are
listed in the same order regardless of version - making On No Data the 5th
event.


--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Lasse T said:
Ok. Thank you. Your aswer tells me that I was wrong. I´m not missing
anything. This is the way I always thought is should be done. You always
enter code in somethings event. I thought there was someoteher way that I
missed. My next problem I have to figure out myself I think. I´m using a
swedish Access and I cannot find any event that means On No Data. I should
be Vid Ingen Data or something like that in swedish. Perheaps someone from
sweden reads this.

Thank you very much for helping me straiten this out.

Lasse T
--------------
 
L

Lasse T

Ok. I found On No Data in the report propertys. The problem
is that I´m trying to do this with a form. Is this possible?
I do not want the form to open if there is no data in it.

Lasse
-------------

Cheryl Fischer said:
Lasse,

So, open your Report in Design View, then:

1. Press ALT-Enter to open the Property Sheet for the report.

2. You will see another form with a ComboBox at the top which says
"Report".
Leave that one alone. Below the ComboBox is a set of Tabs. Click the one
that says "Events".

3. In the grid below, locate the row labeled, On No Data. It should be
blank. Click anywhere in the white space to the right of the label and you
will see a downward-pointing arrow appear, indicating that this is also a
ComboBox. Click the arrow and select "Event Procedure".

4. Then, notice that there is an ellipsis or three little dots (...) to the
right of the ComboBox. Click the ellipsis and you will open a code window.
You will see that Access has given you a space for entering some code in
this event - it will look something like the following:

Private Sub Report_NoData(Cancel As Integer)

End Sub

5. After the "Private Sub Report_NoData(Cancel As Integer)" line,
insert the code that Jeff provided:

Save and close the module.

hth,
--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Lasse T said:
Hi all !!

I hope someone are willing to help me explain something.

I have been playing around with Access for some time but when it comes to
VBA i am a total newbie. I get around by searching the web and Usenet
when
 
C

Cheryl Fischer

You can put the following in the On Load event of the form:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records to display."
DoCmd.Close
End If


--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Lasse T said:
Ok. I found On No Data in the report propertys. The problem
is that I´m trying to do this with a form. Is this possible?
I do not want the form to open if there is no data in it.

Lasse
-------------
 
R

Rolls

Some Access developers will set up a code module (see Module window) and put
all VBA code there instead of having it scattered all over, which
standardizes development and makes code slightly more portable across
applications.

It's also possible to do an entire application without a code module as you
appear to have been doing.

Your choice.
 

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