473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MS access

Sub PreviewReport_Click()
On Error GoTo Err_PreviewReport_Click

Dim stRepName As String: Rem Holds the Report name
Dim stDispId As String: Rem Holds the Dispenser ID
Dim stQuery As String: Rem Holds the Query name
Dim stWhere As String: Rem Holds the where clause
Dim stExtra As String:
Dim stMonthYear, stYear, stWeekCount As String
Dim intX As Integer, rst As Recordset
Dim dtEndDate As Date

stRepName = Form.cbReports

If IsNull(Form.cbDispenser) Then
MsgBox ("Please pick a Dispenser.")
GoTo Exit_PreviewReport_Click
End If

stDispId = Form.cbDispenser
stWhere = ""

If IsNull(Form.cbMonthYear) Then
MsgBox ("Please pick a Month")
GoTo Exit_PreviewReport_Click
Else
stMonthYear = Form.cbMonthYear
stYear = Format(CDate("1 " & Form.cbMonthYear), "yyyy")
End If


dtEndDate = Nz(DMax("EndDate", "Dispensers", "[ID] = " & stDispId), cLowDate)






If stRepName = "Weekly Dispenser Sales" Then
stQuery = "Weekly Dispenser Sales"
stWhere = "format(START_DT,""MMMM YYYY"") = """ + stMonthYear + """"
ElseIf stRepName = "Individual Weekly Sales" Then: Rem Sheet 8
If dtEndDate <> cLowDate And _
Format(dtEndDate, "YYYYMMDD") < Format(CDate(cbMonthYear), "YYYYMMDD") Then

MsgBox ("There are no records for this Dispenser in this month")
Exit Sub

Else
stQuery = "Individual Weekly Sales"
stExtra = "DISPENSERS.Disabled = ""no"" "
stWhere = "SALES.DISPENSER_ID = " + stDispId + " and format(START_DT,""MMMM YYYY"") = """ + stMonthYear + """ and "DISPENSERS.Disabled = ""no"" """""""
End If
ElseIf stRepName = "Company Weekly Sales" Then
stQuery = "Company Weekly Sales"
stExtra = " AND DISPENSERS.Disabled = ""no"" "
stWhere = "MonthYear= """ + stMonthYear + """" + stExtra
ElseIf stRepName = "Company Monthly Sales" Then
stQuery = "Company Monthly Sales"
stWhere = "Year= " & stYear
ElseIf stRepName = "Company Year End" Then
stQuery = "Company Year End"
stWhere = "SALES.WorkingWeek=-1"
ElseIf stRepName = "Dispenser Comparison Monthly" Then: Rem Sheet 11
stQuery = "Dispenser Comparison Monthly"
stWhere = "MonthYear= """ + stMonthYear + """"
ElseIf stRepName = "Dispenser Comparison Yearly" Then
stQuery = "Dispenser Comparison Yearly"
stWhere = "Year= " & stYear & " and SALES.WorkingWeek =-1"
ElseIf stRepName = "Individual Monthly Sales" Then
If dtEndDate <> cLowDate And _
Format(dtEndDate, "YYYY") < Format(CDate(cbMonthYear), "YYYY") Then

MsgBox ("There are no records for this Dispenser in this year")
Exit Sub
Else
stQuery = "Individual Monthly Sales"
stWhere = "DISPENSER_ID=" & stDispId & " and Year = " & stYear
End If
ElseIf stRepName = "Individual Year End" Then
stQuery = "Individual Year End"
stWhere = "DISPENSERID=" & stDispId & " and SALES.WorkingWeek = -1"
End If

DoCmd.OpenReport stRepName, acPreview, stQuery, stWhere

Exit_PreviewReport_Click:
Exit Sub

Err_PreviewReport_Click:
MsgBox Err.Description
Resume Exit_PreviewReport_Click

End Sub

the above code is for when a preview report button is pushed in the main menu.

basically what i wanted the button to do, ws to show the corosponding reports, but it runs and a parameter box opens and asks for DISPENSER.DISABLED, iv tried defining in the code, but to no joy, sometimes i get the error, variable not defined, sometimes type mismatch, its driving me crazy now.

basically the DISPENSER.DISABLED colum ws added so that when a dispenser is deleted, they are just put as disabled and not deleted off completly,any help would be a plus, sorry if im not clear, its first time on a forum.

many thanks
Mar 20 '07 #1
5 1553
Rabbit
12,516 Expert Mod 8TB
Can you post the metadata of your table?

Expand|Select|Wrap|Line Numbers
  1. Table Name
  2. [Field Name]; Data Type; PK/FK
Mar 20 '07 #2
Can you post the metadata of your table?

Expand|Select|Wrap|Line Numbers
  1. Table Name
  2. [Field Name]; Data Type; PK/FK

metadata?

surename - text
formename - text
ID-auto
addr - text
post code - text
home no - text
start date date/time
full time - tes/no
end date - date time
disabled - text


PERIOD table

start_dt date/time
end_dt date/time
id - aut
working week - yes/no

Sales

ID- AUTO
Dispenser ID- number
perido_id- number
sales- number
sales_units- number
sales_value- number
philips- number
fitted- number
fitted_units- number
fitted_value- number
done- number
booked- number
booked_next - number
workingweek - yes/no

there is the SQL of the dispenser NOT disabled query

SELECT *
FROM DISPENSERS
WHERE Disabled="No"
ORDER BY DISPENSERS.Disabled;

but i just dont know how to stop the PARAMETER BOX appearing, or if it does appear, then for it to show the right info if the right text is entered.
Mar 21 '07 #3
Rabbit
12,516 Expert Mod 8TB
I haven't taken a look yet but a parameter box means that it found a variable that does not exist in your table or that you have not created so it brings up the box for the user to define the unknown variable.
Mar 21 '07 #4
I haven't taken a look yet but a parameter box means that it found a variable that does not exist in your table or that you have not created so it brings up the box for the user to define the unknown variable.

well if you could please take a look, yeah i was thinkin that was wt ws up.
but im not quite sure how to define a variable in the visual basic build??
Mar 22 '07 #5
Rabbit
12,516 Expert Mod 8TB
metadata?

surename - text
formename - text
ID-auto
addr - text
post code - text
home no - text
start date date/time
full time - tes/no
end date - date time
disabled - text


PERIOD table

start_dt date/time
end_dt date/time
id - aut
working week - yes/no

Sales

ID- AUTO
Dispenser ID- number
perido_id- number
sales- number
sales_units- number
sales_value- number
philips- number
fitted- number
fitted_units- number
fitted_value- number
done- number
booked- number
booked_next - number
workingweek - yes/no

there is the SQL of the dispenser NOT disabled query

SELECT *
FROM DISPENSERS
WHERE Disabled="No"
ORDER BY DISPENSERS.Disabled;

but i just dont know how to stop the PARAMETER BOX appearing, or if it does appear, then for it to show the right info if the right text is entered.
Assuming that first table you posted is called dispensers and that dispensers is a text field can be either "No" or "Yes", why would you order by the disabled field?
Mar 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
13
by: bill | last post by:
I am trying to convince a client that dotNet is preferable to an Access project (ADP/ADE). This client currently has a large, pure Access MDB solution with 30+ users, which needs to be upgraded....
1
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
13
by: Simon Bailey | last post by:
I am a newcomer to databases and am not sure which DBMS to use. I have a very simplified knowledge of databases overall. I would very much appreciate a (simplifed) message explaining the advantages...
0
by: Frederick Noronha \(FN\) | last post by:
---------- Forwarded message ---------- Solutions to Everyday User Interface and Programming Problems O'Reilly Releases "Access Cookbook, Second Edition" Sebastopol, CA--Neither reference book...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
64
by: John | last post by:
Hi What future does access have after the release of vs 2005/sql 2005? MS doesn't seem to have done anything major with access lately and presumably hoping that everyone migrates to vs/sql. ...
1
by: com | last post by:
Extreme Web Reports 2005 - Soft30.com The wizard scans the specified MS Access database and records information such as report names, parameters and subqueries. ......
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
37
by: jasmith | last post by:
How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.