Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert this Working code in Module (For Report)

Status
Not open for further replies.

replyrpatil

Programmer
Apr 28, 2007
24
US
I need to compare two image reports side by side and if there is a change I need to indicate if there is change or no change.

Main report has two sub report (rptPIactiveImages and rptPIInProcessImages )

rptPIactiveImages has following filed name (All the four have height set to zero.)

1) FiledName
2) Filed Image ( which is besides the filed name and the Image is named as “IMfiledName”)
3) Image Change NoChange ( Which is besides the Filed Image that puts a greenArrow image for no change and redarrow image for change) this filed is named as “IMCfiledName”
4) Push Field --- Because I cannot set the Image to Can Grow and Can Shrink , I have put a filed beside the IMCfiledName , if there is a image I am changing the its value that will push the next image down. This filed has Can Grow value set to true. This is named as “exFiledName”

rptPIInProcessImages is copy paste of the rptPIactiveImages and later I have deleted “Image Change NoChange” filed.


rptPIactiveImages and rptPIInProcessImages is pulling information from two different query based on same table with different filter criteria ( One filters the ACTIVE information and other filters INPROCESS information)

What I am doing is just comparing these Image values and showing them side by side .

The following code works fine for me but the problem is that I have about 37 different filed values that I need to compare and I do not want to Copy Paste the same code 37 time just changing the filed values.

I WANT TO CONVER THIS CODE IN A MODULE AND CALL IT LIKE

Call VerifyIMGChange (CASETIF)

Call VerifyIMGChange (DATATIF)


Etc……………………………..



If Nz(Me.rptPIactiveImages.Report.CASETIF, "") <> "" Or Nz(Me.rptPIInProcessImages.Report.CASETIF, "") <> "" Then
If Nz(Me.rptPIactiveImages.Report.CASETIF, "") <> "" Then
s1 = Me.rptPIactiveImages.Report.CASETIF
Else
s1 = "notanimage"
End If
If Nz(Me.rptPIInProcessImages.Report.CASETIF, "") <> "" Then
s2 = Me.rptPIInProcessImages.Report.CASETIF
Else
s2 = "notanimage"
End If
img1 = Right([s1], 4)
img2 = Right([s2], 4)
If img1 = ".TIF" Or img2 = ".TIF" Then
Me.rptPIactiveImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.ImcCASETIF.Picture = "(none)"
Me.rptPIInProcessImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.CASETIF.Visible = True
Me.rptPIactiveImages.Report.ImCASETIF.Visible = True
Me.rptPIactiveImages.Report.ImcCASETIF.Visible = True
Me.rptPIactiveImages.Report.exCASETIF.Visible = True
Me.rptPIInProcessImages.Report.CASETIF.Visible = True
Me.rptPIInProcessImages.Report.ImCASETIF.Visible = True
Me.rptPIInProcessImages.Report.exCASETIF.Visible = True
Me.rptPIactiveImages.Report.ImCASETIF.Height = 2800
Me.rptPIactiveImages.Report.ImCASETIF.Width = 3550
Me.rptPIactiveImages.Report.ImcCASETIF.Height = 2800
Me.rptPIactiveImages.Report.ImcCASETIF.Width = 1200
Me.rptPIInProcessImages.Report.ImCASETIF.Height = 2800
Me.rptPIInProcessImages.Report.ImCASETIF.Width = 3550
Me.rptPIactiveImages.Report.exCASETIF = "VVVVVVVVVVVVV"
Me.rptPIInProcessImages.Report.exCASETIF = "VVVVVVVVVVVVV"
If img1 = ".TIF" Then
Me.rptPIactiveImages.Report.[ImCASETIF].Picture = ImagePath & Me.rptPIactiveImages.Report.CASETIF
Else
Me.rptPIactiveImages.Report.ImCASETIF.Picture = ImagePath & "NoImageAvailable.tif"
End If
If img2 = ".TIF" Then
Me.rptPIInProcessImages.Report.[ImCASETIF].Picture = ImagePath & Me.rptPIInProcessImages.Report.CASETIF
Else
Me.rptPIInProcessImages.Report.ImCASETIF.Picture = ImagePath & "NoImageAvailable.tif"
End If
If Me.rptPIactiveImages.Report.CASETIF = Me.rptPIInProcessImages.Report.CASETIF Then
Me.rptPIactiveImages.Report.[ImcCASETIF].Picture = ImagePath & "GreenArrow.bmp"
Else
Me.rptPIactiveImages.Report.[ImcCASETIF].Picture = ImagePath & "redarrow.bmp"
End If
Else
Me.rptPIactiveImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.ImcCASETIF.Picture = "(none)"
Me.rptPIInProcessImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.CASETIF.Visible = False
Me.rptPIactiveImages.Report.ImCASETIF.Visible = False
Me.rptPIactiveImages.Report.ImcCASETIF.Visible = False
Me.rptPIactiveImages.Report.exCASETIF.Visible = False
Me.rptPIInProcessImages.Report.CASETIF.Visible = False
Me.rptPIInProcessImages.Report.ImCASETIF.Visible = False
Me.rptPIInProcessImages.Report.exCASETIF.Visible = False
End If
Else
Me.rptPIactiveImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.ImcCASETIF.Picture = "(none)"
Me.rptPIInProcessImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.CASETIF.Visible = False
Me.rptPIactiveImages.Report.ImCASETIF.Visible = False
Me.rptPIactiveImages.Report.ImcCASETIF.Visible = False
Me.rptPIactiveImages.Report.exCASETIF.Visible = False
Me.rptPIInProcessImages.Report.CASETIF.Visible = False
Me.rptPIInProcessImages.Report.ImCASETIF.Visible = False
Me.rptPIInProcessImages.Report.exCASETIF.Visible = False
End If

 
Not sure if I totally follow you, but you can either pass the controls name or the control itself. For many people it is easier to pass the name since it is not an object. My example will pass the name. If I am following, it looks like you are comparing a field from the active subform and a field from the process subform. So if you want to do this same comparison with different fields you need to pass in the name of the active control and the process control. Also take a look at the "With, End With" construct you could save a ton of typing.

VerifyIMGChange ("yourActiveCntrlName","yourProcessCntrlName")

now use the control collection in your code

Code:
public sub VerifyIMGChange (strActive as string, strProcess as string)
 dim cntrlActive as access.control
 dim cntrlProcess as access.control
 'set the controls
 set cntrlActive = Me.rptPIactiveImages.Report.controls(strActive)
  set cntrlProcess = Me.rptPIactiveImages.Report.controls(strProcess) 
'now instead of something like this
' Me.rptPIactiveImages.Report.ImCASETIF.Picture = "(none)"
'simply
  cntrlActive.picture = "(none)"
end sub

You really should encapsultate this code to make it easier to work with. I would have the minimum functions that return a boolean value

fncIsImage(Cntrl as access.control)
a function that returns if it is an image

Then you could in your code do:
if fncIsImage(cntrlActive) then ...

fncIsTIF(Cntrl as access.control)
if fncIsTIF(cntrlProcess) then

I would also have seperate subs for some of your other processing.

The with end with looks like this
old:
Me.rptPIactiveImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.ImcCASETIF.Picture = "(none)"
Me.rptPIInProcessImages.Report.ImCASETIF.Picture = "(none)"
Me.rptPIactiveImages.Report.CASETIF.Visible = False
Me.rptPIactiveImages.Report.ImCASETIF.Visible = False
Me.rptPIactiveImages.Report.ImcCASETIF.Visible = False
Me.rptPIactiveImages.Report.exCASETIF.Visible = False
Me.rptPIInProcessImages.Report.CASETIF.Visible = False
Me.rptPIInProcessImages.Report.ImCASETIF.Visible = False
Me.rptPIInProcessImages.Report.exCASETIF.Visible = False

with me.rptPIactiveImages.Report
.ImCASETIF.Picture = "(none)"
.ImcCASETIF.Picture = "(none)"
.ImCASETIF.Picture = "(none)"
.CASETIF.Visible = False
.ImCASETIF.Visible = False
.ImcCASETIF.Visible = False
.exCASETIF.Visible = False
.CASETIF.Visible = False
.ImCASETIF.Visible = False
.exCASETIF.Visible = False
end with

 
If you want to pass the actual controls then

Code:
public sub VerifyIMGChange (cntrlActive as Access.control, cntrlProcess as access.control)
end sub

To pass the control in

call VerifyIMGChange ( Me.rptPIactiveImages.Report.ImCASETIF,Me.rptPIInProcessImages.Report.ImCASETIF)
 
sorry my with, end with was a little misleading. I did not see they were from different subforms. More Like.

with me.rptPIactiveImages.Report
.ImCASETIF.Picture = "(none)"
.ImcCASETIF.Picture = "(none)"
.CASETIF.Visible = False
.ImCASETIF.Visible = False
.ImcCASETIF.Visible = False
.exCASETIF.Visible = False
end with

with me.ptPIInProcessImages.Report
.ImCASETIF.Picture = "(none)"
.CASETIF.Visible = False
.ImCASETIF.Visible = False
.exCASETIF.Visible = False
end with
 
I did this ( see bellow) but it gives me

Compile Error :

ByRef argument type mismatch


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


Sub VerifyIMGChange(FldA As Control, FldIP As Control, FldC As Control)
Dim ImFldA As Control
Dim ImcFldA As Control
Dim exFldA As Control

Dim ImFldIP As Control
Dim ImcFldIP As Control
Dim exFldIP As Control

Set FldA = Me.rptPIactiveImages.Report.Controls(FxA.Name)
Set ImFldA = Me.rptPIactiveImages.Report.Controls("IM" & FldA.Name)
Set ImcFldA = Me.rptPIactiveImages.Report.Controls("IMc" & FldA.Name)
Set exFldA = Me.rptPIactiveImages.Report.Controls("ex" & FldA.Name)

Set FldIP = Me.rptPIInProcessImages.Report.Controls(FxA.Name)
Set ImFldIP = Me.rptPIInProcessImages.Report.Controls("IM" & FldIP.Name)
Set ImcFldIP = Me.rptPIInProcessImages.Report.Controls("IMc" & FldIP.Name)
Set exFldIP = Me.rptPIInProcessImages.Report.Controls("ex" & FldIP.Name)


Dim s1 As String
Dim s2 As String
Dim img1 As String
Dim img2 As String
Dim ImagePath As String
ImagePath = "C:\Wineasy\BAS\IMG\"

If Nz(FldA.Value, "") <> "" Or Nz(FldIP.Value, "") <> "" Then
If Nz(FldA.Value, "") <> "" Then
s1 = FldA.Value
Else
s1 = "notanimage"
End If
If Nz(FldIP.Value, "") <> "" Then
s2 = FldIP.Value
Else
s2 = "notanimage"
End If
img1 = Right([s1], 4)
img2 = Right([s2], 4)
If img1 = ".TIF" Or img2 = ".TIF" Then
ImFldA.Picture = "(none)"
ImcFldA.Picture = "(none)"
ImcFldIP.Picture = "(none)"
FldA.Visible = True
ImFldA.Visible = True
ImcFldA.Visible = True
exFldA.Visible = True
FldIP.Visible = True
ImFldIP.Visible = True
exFldIP.Visible = True
ImFldA.Height = 2800
ImFldA.Width = 3550
ImcFldA.Height = 2800
ImcFldA.Width = 1200
ImFldIP.Height = 2800
ImFldIP.Width = 3550
exFldA = "VVVVVVVVVVVVV"
exFldIP = "VVVVVVVVVVVVV"
If img1 = ".TIF" Then
ImFldA.Picture = ImagePath & FldA
Else
ImFldA.Picture = ImagePath & "NoImageAvailable.tif"
End If
If img2 = ".TIF" Then
ImFldIP.Picture = ImagePath & FldIP
Else
ImFldIP.Picture = ImagePath & "NoImageAvailable.tif"
End If
If FldA = FldIP Then
ImcFldA.Picture = ImagePath & "GreenArrow.bmp"
Else
ImcFldA.Picture = ImagePath & "redarrow.bmp"
End If
Else
ImFldA.Picture = "(none)"
ImcFldA.Picture = "(none)"
ImFldIP.Picture = "(none)"
FldA.Visible = False
ImFldA.Visible = False
ImcFldA.Visible = False
exFldA.Visible = False
FldIP.Visible = False
ImFldIP.Visible = False
exFldIP.Visible = False
End If
Else
ImFldA.Picture = "(none)"
ImcFldA.Picture = "(none)"
ImFldIP.Picture = "(none)"
FldA.Visible = False
ImFldA.Visible = False
ImcFldA.Visible = False
exFldA.Visible = False
FldIP.Visible = False
ImFldIP.Visible = False
exFldIP.Visible = False
End If

End Sub



 
I would need to see how you are calling the procedure. It is asking for three controls, are you passing three controls? If you pass an object or variable that is not a control you will get this error. Also place this procedure in a standard module not a forms module. I think if this procedure is in a forms module when you pass the control it will actually resolve the controls value and pass only the value.
 
This VerifyIMGChange in a sub module in report .

On format I call it like

Call VerifyIMGChange ( PRODIMAGE , PRODIMAGE , PRODIMAGE)


because the InProcess and Active sub forms are driven from queries based on same table it will have the same control name



 
You have two different things going on. It looks like you mixed them. You can either pass in the name of the control and then set it to a control, or you can pass in the control.

Method 1.

From the form something like
Code:
private sub someEvent()
  call VerifyIMGChange("name1","name2","name3")
end sub
Then your sub
Code:
Sub VerifyIMGChange(FldAName As string, FldIPName As string, FldCName As string)

'However the bottom line of code makes no sense to me
'you pass in FldA, but then attempt to incorrectly set it
'to FxA.  This would negate any reason of passing in the 
'control or the control name. Maybe this is leftover. If you put this code in a 'standard module you can not use the Me keyword you will 'have to use the Reports collection 
Set FldA = Me.rptPIactiveImages.Report.Controls(FxA.Name)
'Any way use the name here that was passed in
Set ImFldA = Me.rptPIactiveImages.Report.Controls("IM" & FldAName)
Set ImcFldA = Me.rptPIactiveImages.Report.Controls("IMc" & FldAName)
Set exFldA = Me.rptPIactiveImages.Report.Controls("ex" & FldAName)

I do not get how this works. Are you always passing in the name "ProdImage", because then I do not understand why even pass it in? Are there other image controls that could get passed in?
37 different field values that I need to compare and I do not want to Copy Paste the same code 37 time just changing the filed values
Can you explain that better? What field values are you talking about?


There does not seem a reason to pass the actual control based on the way you have this set up because all you do is then get the name and use it to set other controls. Also if it always the same three names you would only need the single parameter. However, so that you know if you want to pass a control you have to do something like this or you will get your byref error.
Code:
private sub someEventOnyourForm()
  dim cntrlA as access.control
  set cntrlA = Me.rptPIactiveImages.Report.cntrlName 
  call VerifyIMGChange(cntrlA)
end sub

Public sub VerifyIMGChange (cntrlA as acess.cntrl)
  'do not need to set or reference just work with it since
  'it is a control
  cntrlA.value = 1234
end sub
What you can not do is the following
Code:
private sub someEventOnyourForm()
   call VerifyIMGChange(Me.rptPIactiveImages.Report.cntrlName )
end sub
although it looks like you are passing the control it will in fact pass the value of the control and thus give the byref error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top