A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Open A reprt with Conditions from a subform



 
 
Thread Tools Display Modes
  #1  
Old August 13th, 2005, 06:45 PM
Alvin
external usenet poster
 
Posts: n/a
Default Open A reprt with Conditions from a subform

I have the following code in the On Open Event of a Report. I am new to VB
Code but am learning. I can get one condition to work when I use it Like this.

----------- It Works Like This---------------

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
End If
End Sub
---------------------------------------------------------------------------------------

but I don't know how to add the second or third. Here are the conditions
and actual names I want to use something Like the following where I can Make
sure needed field have been entered before viewing the Report.

----------------This way I can't get it to work---------------------

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
If IsNull(Forms!Breeders![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & Chr(13) &
Chr(10) & Chr(10) & "You Have Chosen ( " & [Breeders
subform].Form![BreadFemale].Column(1) & " ) To Breed With ( " &
[Form_Breeders]![Name] & " ) You Must Now Enter a Breed Date! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
End If
End If
End Sub

----------------------------------------------------------------

Thanks in Advance
Alvin Smith
  #2  
Old August 13th, 2005, 08:45 PM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Alvin,

The general concept you are aiming at is *almost* there. I think it
would work like this...

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
ElseIf IsNull(Forms!Breeders![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & Chr(13) &
Chr(10) & Chr(10) & "You Have Chosen ( " & [Breeders
subform].Form![BreadFemale].Column(1) & " ) To Breed With ( " &
[Form_Breeders]![Name] & " ) You Must Now Enter a Breed Date! ",
vbInformation, "Breed Manager"
Cancel = -1
End If
End Sub

However, a few comments that are hpefully helpful...

- I am surprised that this section of your code works:
..To Breed With ( " & [Form_Breeders]![Name] & " )
I would have expected you to need Forms![Form_Breeders]![Name]

- In any case, Name is a Reserved Word (i.e. has a special meaning) in
Access, and it is strongly recommended not to use it as the name of a
field or control or database object.

- In code, I think it is preferable to use vbCrLf in the place of
Chr(13) & Chr(10)

- Instead of waiting for the Open event of the report, I would do this
validation on the event that triggers the opening of the report. For
example, from what you have told us so far, I would imagine there is a
command button that you click on the Breeders form to run the report, or
some other form-based event to run the report... am I right? If so, you
could do like this...

Private Sub YourButton_Click()
If IsNull(Me![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value." &
vbCrLf & "You Must Select A Female to Breed With ( " & Me![TheName] & ")
before you can View This Report!", vbInformation, "Breed Manager"
ElseIf IsNull(Me![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & vbCrLf & "You
Have Chosen ( " & Me![Breeders subform].Form![BreadFemale].Column(1) &
") To Breed With ( " & Me![TheName] & ") You Must Now Enter a Breed
Date!", vbInformation, "Breed Manager"
Else
DoCmd.OpenReport "YourReport"
End If
End Sub

--
Steve Schapel, Microsoft Access MVP


Alvin wrote:
I have the following code in the On Open Event of a Report. I am new to VB
Code but am learning. I can get one condition to work when I use it Like this.

----------- It Works Like This---------------

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
End If
End Sub
---------------------------------------------------------------------------------------

but I don't know how to add the second or third. Here are the conditions
and actual names I want to use something Like the following where I can Make
sure needed field have been entered before viewing the Report.

----------------This way I can't get it to work---------------------

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
If IsNull(Forms!Breeders![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & Chr(13) &
Chr(10) & Chr(10) & "You Have Chosen ( " & [Breeders
subform].Form![BreadFemale].Column(1) & " ) To Breed With ( " &
[Form_Breeders]![Name] & " ) You Must Now Enter a Breed Date! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
End If
End If
End Sub

----------------------------------------------------------------

Thanks in Advance
Alvin Smith

  #3  
Old August 13th, 2005, 09:23 PM
Alvin
external usenet poster
 
Posts: n/a
Default

Thank you steve, Someone else suggested changing Name to something else and I
will do that but I gotta be ready because I am afraid of loosing my links,
Everyone can't be wrong lol:-)! Besides I am still learning.
By the way.
On my subform I have a checkBox and on the main form I have a CmdButton that
opens a Form called Notes. Lets say a user selects a record in the subform
and then clicks on the CmdButton to add notes about that record. How can I
have the checkBox automaticaly insert a check that way the user will know
there are notes pertaining to that record.
SHewwwww I hope I explained that correctly.
Thanks again Steve
"Steve Schapel" wrote:

Alvin,

The general concept you are aiming at is *almost* there. I think it
would work like this...

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
ElseIf IsNull(Forms!Breeders![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & Chr(13) &
Chr(10) & Chr(10) & "You Have Chosen ( " & [Breeders
subform].Form![BreadFemale].Column(1) & " ) To Breed With ( " &
[Form_Breeders]![Name] & " ) You Must Now Enter a Breed Date! ",
vbInformation, "Breed Manager"
Cancel = -1
End If
End Sub

However, a few comments that are hpefully helpful...

- I am surprised that this section of your code works:
..To Breed With ( " & [Form_Breeders]![Name] & " )
I would have expected you to need Forms![Form_Breeders]![Name]

- In any case, Name is a Reserved Word (i.e. has a special meaning) in
Access, and it is strongly recommended not to use it as the name of a
field or control or database object.

- In code, I think it is preferable to use vbCrLf in the place of
Chr(13) & Chr(10)

- Instead of waiting for the Open event of the report, I would do this
validation on the event that triggers the opening of the report. For
example, from what you have told us so far, I would imagine there is a
command button that you click on the Breeders form to run the report, or
some other form-based event to run the report... am I right? If so, you
could do like this...

Private Sub YourButton_Click()
If IsNull(Me![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value." &
vbCrLf & "You Must Select A Female to Breed With ( " & Me![TheName] & ")
before you can View This Report!", vbInformation, "Breed Manager"
ElseIf IsNull(Me![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & vbCrLf & "You
Have Chosen ( " & Me![Breeders subform].Form![BreadFemale].Column(1) &
") To Breed With ( " & Me![TheName] & ") You Must Now Enter a Breed
Date!", vbInformation, "Breed Manager"
Else
DoCmd.OpenReport "YourReport"
End If
End Sub

--
Steve Schapel, Microsoft Access MVP


Alvin wrote:
I have the following code in the On Open Event of a Report. I am new to VB
Code but am learning. I can get one condition to work when I use it Like this.

----------- It Works Like This---------------

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
End If
End Sub
---------------------------------------------------------------------------------------

but I don't know how to add the second or third. Here are the conditions
and actual names I want to use something Like the following where I can Make
sure needed field have been entered before viewing the Report.

----------------This way I can't get it to work---------------------

Private Sub Report_Open(Cancel As Integer)
If IsNull(Forms!Breeders![Breeders subform].Form!MatingOrderID) Then
MsgBox "You Have Chosen a Mating Order That Has No Value. " &
Chr(13) & Chr(10) & Chr(10) & "You Must Select A Female to Breed With ( " &
[Form_Breeders]![Name] & " ) before you can View This Report! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
If IsNull(Forms!Breeders![Breeders subform].Form![BreadFemale]) Then
MsgBox "You Must Choose A Female To Be Bred! " & Chr(13) &
Chr(10) & Chr(10) & "You Have Chosen ( " & [Breeders
subform].Form![BreadFemale].Column(1) & " ) To Breed With ( " &
[Form_Breeders]![Name] & " ) You Must Now Enter a Breed Date! ",
vbInformation, "Breed Manager"
Cancel = -1
Else
End If
End If
End Sub

----------------------------------------------------------------

Thanks in Advance
Alvin Smith


  #4  
Old August 13th, 2005, 09:36 PM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Alvin,

Me.MySubform.Form!MyCheckbox = -1

Might be better to have the command button on the subform, I would say.

--
Steve Schapel, Microsoft Access MVP

Alvin wrote:
Thank you steve, Someone else suggested changing Name to something else and I
will do that but I gotta be ready because I am afraid of loosing my links,
Everyone can't be wrong lol:-)! Besides I am still learning.
By the way.
On my subform I have a checkBox and on the main form I have a CmdButton that
opens a Form called Notes. Lets say a user selects a record in the subform
and then clicks on the CmdButton to add notes about that record. How can I
have the checkBox automaticaly insert a check that way the user will know
there are notes pertaining to that record.
SHewwwww I hope I explained that correctly.
Thanks again Steve

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a subform to display and add info into table ivalum21 Using Forms 19 March 17th, 2010 09:36 AM
Form, Subform, Tab key 2nd_Stage_User Using Forms 17 August 25th, 2006 12:30 AM
Open form based on Mainform and Subform Brian New Users 1 June 25th, 2005 11:06 PM
how to click a subform (datasheet view) to open another subform Jeff Using Forms 1 April 6th, 2005 12:03 PM
Subform Refresh Problem (but only with an unbound combo box control) Barry Skidmore Using Forms 1 December 21st, 2004 01:19 AM


All times are GMT +1. The time now is 12:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.