Why has this stopped working

D

DDawson

I have an inspections database and one of the forms has stopped working. Can
you please help me to fix it.

The form, when it works, allows the user to select multiple sites from a
list and when the print button is pressed, prints the survey results for the
selected sites. The form also has a tickbox, set to yes by default, which
allows the user to preview the report when the print button is pressed.

I currently get an error highlighting Trim... (line 10) the error message
states "compile error can't find project or library". I think this may be due
to me working on it at home, because when I try it at my work's computer I
get an error at DoCmd (the second last line) line, where it highlights
strCriteria.

Here is the code behind the print button:
btw. mslbxSites refers to the fom's multi-select listbox containing a list
of all the sites.

Private Sub btnPrintReport_Click()
Dim vItm As Variant
Dim strCriteria As String
Dim intView As Integer
Dim intWindowMode As Integer

strCriteria = "[Site] In ("
For Each vItm In Me!mslbxSites.ItemsSelected
strCriteria = strCriteria & "'" & _
Trim(Me!mslbxSites.ItemData(vItm)) & "', "
Next vItm
strCriteria = Left(strCriteria, Len(strCriteria) - 2) & ")"
'For CheckBox named ckPreview, where Default=True
If ckPreview Then
intView = acPreview
intWindowMode = acDialog
Else
intView = acViewNormal
intWindowMode = acWindowNormal
End If
DoCmd.OpenReport "rptSiteSurvey", intView, strCriteria, intWindowMode
End Sub

I hope this is enough for you more experienced guys to identify the problem,
please let me know if you need any more info.

Kind regards
Dylan Dawson
 
M

Maury Markowitz

Are any of your References on a network share? If so, reconnect to it.
I had similar errors where Excel would tell me "Nz" no longer existed,
with the same message. Interestingly, the library that had been
disconnected (for less than 1 second from what I could tell) did not
contain Nz, but it's quick disappearance made VBA get really confused.

Maury
 
A

Arvin Meyer MVP

I currently get an error highlighting Trim... (line 10) the error message
states "compile error can't find project or library". I think this may be
due
to me working on it at home, because when I try it at my work's computer I
get an error at DoCmd (the second last line) line, where it highlights
strCriteria.

That error is due to a missing reference. Open any code window and on your
menu, go to Tools >>> References and look for the one marked as "MISSING".
Either delete the reference (if you don't need it) or find it by navigating
to it with the Browse button.
 
T

Tony Toews [MVP]

DDawson said:
I currently get an error highlighting Trim... (line 10) the error message
states "compile error can't find project or library".

References error.

Do you have any references besides the basics? Are you sure you need
them? Write down the path and name of the extra ones (or put the
following code in a module and execute the code), delete from the
references list and Compile and Save All. Keep any necessary
references and ensure they are distributed to the target system.

Sub ViewReferenceDetails()

Dim ref As Reference

For Each ref In Access.References
Debug.Print ref.Name & " - " & ref.Major & "." & ref.Minor & "
- " & ref.FullPath
Next ref

End Sub

For a very detailed page on reference problems see
http://www.accessmvp.com/djsteele/AccessReferenceErrors.html

Ctrl+G will take you into the Debug/Immediate window. Then click on
Tools on the menu bar and References.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
D

DDawson

Thanks. I found a reference to Microsoft Outlook, which was reported as
missing.

Can you please help me with the next part, to get it to work properly?

Now, when I hit print (preview) it prints a report of every site, instead of
the ones I've selected. I examined the report "rptSiteSurvey" and I find that
the report refers to a query called "qrySiteSurveyPrint". When I look into
the queries, I also find another query exists called "qrySiteSurveyPreview".

Can you have a look at them for me and advise why it doesn't printing only
the sites I select from "frmSiteSurveyReport". here is the SQL behind both
queries:

QrySiteSurveyPreview

SELECT SurveyData.[Date of Survey], SurveyData.Site, SurveyData.Element,
SurveyData.Condition, SurveyData.PriorityRef, SurveyData.[Revenue Cost],
SurveyData.[Revenue Comments], SurveyData.[Remaining Life],
SurveyData.[Capital Cost], SurveyData.[Capital Comments]
FROM SurveyData
WHERE (((SurveyData.Site)=[frmSiteSurveyRpt]![lstSelectSite]))
ORDER BY SurveyData.[Date of Survey], SurveyData.Site, SurveyData.Element;


QrySiteSurveyPrint

SELECT SurveyData.[Date of Survey], SurveyData.Site, SurveyData.Element,
SurveyData.Condition, SurveyData.PriorityRef, SurveyData.[Revenue Cost],
SurveyData.[Revenue Comments], SurveyData.[Remaining Life],
SurveyData.[Capital Cost], SurveyData.[Capital Comments]
FROM SurveyData
ORDER BY SurveyData.[Date of Survey], SurveyData.Site, SurveyData.Element;

Kind regards
Dylan Dawson
 
D

DDawson

Thanks, I've created a new post with subject "Print selected records" to
request assistance and at the same time help others with similar problems.

DDawson
 

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