Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > VB/SQL Access Report Query


Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2002, 05:12 AM
jasveer
Guest
 
Posts: n/a
Unhappy VB/SQL Access Report Query


I am using VB with an Access Relational Database

I have several forms with command buttons allowing records to be added etc....


What I want to happen when I click a command button called Print Shift Report on the employee shift form is to run a Query already created and saved in Access.

Can this be done and how much is involved in completing such a task...??

Any help would be greatly appreciated...
Reply With Quote
  #2  
Old 04-26-2002, 07:14 AM
sachin
Guest
 
Posts: n/a
Default

Hi
Running any query when u click the command button is not a problem. but how you will format the report???
please ellaborate your question.

sachin
Reply With Quote
  #3  
Old 04-26-2002, 07:46 AM
jasveer
Guest
 
Posts: n/a
Default

OK i understand what your saying...Can you give me any ideas as to how i could do it.

At the moment I am using VB to add/update records in the access database but am not sure how i could create a similar report in visual basic which would run from a command click.

I am kind of new to VB....

any help would be greatly appreciated...

thanks in advance
Reply With Quote
  #4  
Old 04-26-2002, 08:20 AM
wadair
Guest
 
Posts: n/a
Default

Have you tried setting the command button to run an Access report based on the Query ?
Reply With Quote
  #5  
Old 04-26-2002, 08:22 AM
jasveer
Guest
 
Posts: n/a
Default

sorry to sound off the planet or the something but how would i got about doing that? and would the format of the output report be correct
Reply With Quote
  #6  
Old 04-26-2002, 08:30 AM
wadair
Guest
 
Posts: n/a
Default

Assuming that you already have the query created in Access, you just have to create a report based on that query then set the command button to run the report. When you use the wizard in access it allows you to format the report in several ways. Its kind of a 3 part process....Do you have design access to the database ?
Reply With Quote
  #7  
Old 04-26-2002, 08:32 AM
jasveer
Guest
 
Posts: n/a
Default

yes I have.

The report has already been created in access.
Reply With Quote
  #8  
Old 04-26-2002, 08:34 AM
wadair
Guest
 
Posts: n/a
Default

I programmed mine in Access VB so I set the command button like this

Private Sub Command38_Click()
DoCmd.OpenReport "Report Name", acViewPreview
End Sub
Reply With Quote
  #9  
Old 04-26-2002, 08:40 AM
jasveer
Guest
 
Posts: n/a
Default

okay, How does VB now the location of the report?

how do I enter the path of the report/database
Reply With Quote
  #10  
Old 04-26-2002, 08:43 AM
wadair
Guest
 
Posts: n/a
Default

Are you using a seperate VB app to access the database or are you using VB within the database itself
Reply With Quote
  #11  
Old 04-26-2002, 09:00 AM
jasveer
Guest
 
Posts: n/a
Default

HI! i am using VB app to access the database (access 97) VB V6.0
Reply With Quote
  #12  
Old 04-26-2002, 10:35 AM
Robby's Avatar
Robby Robby is offline
Code Factory

Retired Moderator
* Expert *
 
Join Date: Jan 2001
Location: Montreal, Ca.
Posts: 5,565
Default

You can retrieve reports created in Access, BUT keep in mind that all users will need to install Access on their machine.

Code:
'you need to reference "MS Access 8.0 Object Library" (9.0 for Access 2000)
        
Dim appAccess As Access.Application
        Set appAccess = New Access.Application
        appAccess.OpenCurrentDatabase ("myPathToTheDatabase")
        appAccess.DoCmd.OpenReport "myReport", acPreview, , "myCondition Optional"
        
        appAccess.Quit
        Set appAccess = Nothing
__________________
Visit...Bassic Software
Reply With Quote
  #13  
Old 04-27-2002, 11:15 AM
jasveer
Guest
 
Posts: n/a
Default

Robby...

Lets suppose the report I had created in Access 97 was called employee shift or empshift and, that my database was called jas and saved in c:\jas\jas

What would the code for the shift report command button be? bearing in mind the code you stated previously? And how would I reference the version of access?

thank you in advance
Reply With Quote
  #14  
Old 04-27-2002, 11:24 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

To set a reference, go to the Project menu, and select References.
Find Microsoft Access 8.0 Object Library, check the checkbox and
OK.

In Robby's example, replace "myPathToTheDatabase" with
"c:\jas\jas\jas.mdb". Replace "myReport" with "empshift".
Replace "myCondition Optional" with whatever parameters you
need to pass to make the report run correctly.
__________________
Posting Guidelines
Reply With Quote
  #15  
Old 04-27-2002, 04:39 PM
jasveer
Guest
 
Posts: n/a
Default

Thank You... JUST TO RECAP.

Would this be correct?

Private Sub Empreport_Click()

Dim appAccess As Access.Application
Set appAccess = New Access.Application
appAccess.OpenCurrentDatabase ("c:\jas\jas.mdb")
appAccess.DoCmd.OpenReport "empshift", acPreview, , "myCondition Optional"

appAccess.Quit
Set appAccess = Nothing

End Sub

Secondly, what additional properties do I have to setup for the empreport command button if any?

thank you....
Reply With Quote
  #16  
Old 04-27-2002, 04:47 PM
Robby's Avatar
Robby Robby is offline
Code Factory

Retired Moderator
* Expert *
 
Join Date: Jan 2001
Location: Montreal, Ca.
Posts: 5,565
Default

This line....
Code:
appAccess.DoCmd.OpenReport "empshift", acPreview, , "myCondition Optional"
Should be (if you have no criteria)
Code:
appAccess.DoCmd.OpenReport "empshift", acPreview
Or you can do somthing like this...
Code:
appAccess.DoCmd.OpenReport "empshift", acPreview, , "FirstName = '" & strName & "'"
Where FirstName is a field in the underlying table and srtName is a variable holding a persons' name.
__________________
Visit...Bassic Software
Reply With Quote
  #17  
Old 04-27-2002, 11:47 PM
jasveer
Guest
 
Posts: n/a
Default

thank you i will give it a try
Reply With Quote
  #18  
Old 04-29-2002, 12:23 AM
jasveer
Guest
 
Posts: n/a
Default

Thanks Robby, for that it worked however this is the what I want to happen.

I want to be able to open the report without opening Access (I know this is not possible, unless you know otherwise) therefore, how can I create a text/report file in VB that contains the same fields in the original access report.

Two tables are linked by shiftcode

The tables are

Shift and employeeshift
Prim Key Shiftcode txt field Shiftcode txt field
Day txt field FKey Employeeno txt fld
Type txt field FKey WeekNo

The report should have Shiftcode, WeekNo and Employeeno as headings.


Help!!!!!
Reply With Quote
  #19  
Old 05-02-2002, 01:08 PM
Memnoch1207's Avatar
Memnoch1207 Memnoch1207 is offline
Junior Contributor
 
Join Date: May 2002
Location: Guess! It's really HOT!!
Posts: 314
Default

You can set up a Data Environment linked to your query in Access. Then create a Data Report and place the fields from the query on it. Then everything would work...the report wouldn't be opened with access, it would be opened from within your VB Application.
__________________
He who laughs last...Thinks slowest.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->