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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to VB

Status
Not open for further replies.

Imbriani

Programmer
Joined
Jan 9, 2004
Messages
195
Location
US
Hi all,

I have an Access application that includes the following VBA code to open a report containing just the current record. What I would like to know is how to do this same thing in VB.

stLinkCriteria = "[Lab Number]=" & Me![Lab Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Access runs horribly slow on our system and this is a simple application that I believe will run much more efficiently in VB, but being able to open reports with just the current record is very important to the usability of the program.

I've already been rudely chased out of the VBA forum with this question, so any constructive ideas will be greatly appreciated.

Kathy
 
VBA is (more or less) just an interpreted version of VB, in other words, you can't compile...

the main difference is VBA typically lets you access target application objects, properties and methods with out having to fully qualify them, or in some cases (such as office) setting them...

for example, if DoCmd is an access method...

Add this in VB:
Code:
[b]Dim AxApp As Object
Set AxApp = CreateObject("Access.Application")[/b]
stLinkCriteria = "[Lab Number]=" & Me![Lab Number]
[b]AxApp.[/b]DoCmd.OpenForm stDocName, , , stLinkCriteria

I do not have access, but all the Office API are very similar... so that should at least get you started...

The ME![Lab Number] will probably have to change, since Me in vb refers to the containing form, and not the document...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
How about if I want to completely eliminate Access from this and operate totally in VB. For instance, I want to create an application with a database that when I view Mr. Smith's record, I can open a report by clicking a button that has info on it ONLY from Mr. Smith's record. In other words, the button opens a report that displays info from the current record being viewed in the database. Make sense?

kathy
 
Code:
    stLinkCriteria = "[Lab Number]=" & Me![Lab Number]
    DoCmd.[b]OpenForm[/b] stDocName, , , stLinkCriteria
is to open a form not report in Access. should be
Code:
    stLinkCriteria = "[Lab Number]=" & Me![Lab Number]
    DoCmd.[b]OpenReport[/b] stDocName, , , stLinkCriteria
Imbriani said:
I've already been rudely chased out of the VBA forum with this question, so any co.......
You are talking about thread707-1046815
Kathy, it was not rude at all in my point of view. PHV just informed you to post the appropriate forum.

________________________________________
Zameer Abdulla
Visit Me
There is only one perfect child in this world. Every mother has it.
 
I guess I haven't made this request very clear. What I'm trying to do is to find a way to code in VB the same operation as is done in VBA above. I want to get completely away from the Access program and redo the whole thing into VB6, as Access runs very slowly on our computer network.

I'm trying to find a way to do the same operation, as stated above in VBA, in VB code. I want to get away from the VBA code, also as stated above. If anyone could point me in the right direction, I would appreciate it.

ZmrAbdulla, in response to your take on PVH's comment, I was unsure what forum to post this in, as it involved two separate types of code. His quoting my "any ideas" comment, then commenting on that, came across as rude to me, when simply telling me that I should post this in the VB forum would have not only been helpful, but sufficient. I realize that those of us thrown into the role of writing code when we are not completely familiar with all aspects of it can be irritating to people who do this every day and are very familiar and efficient with it. But there appear to be a lot of us in the same boat and we deeply appreciate a patient attitude and kind words.

kathy

Kathy
 
In order to "completely eliminate Access" you will need to come up to speed on VB forms and the various controls available in VB that facilitate working with databases. As a starter, you need to understand the DAO and/or ADO object models for communicating with a database. You then need to look at datagrids and various other controls that can display and manipulate information in a database.

Access automates a lot of this for you but with "Pure VB" you will need to build your own control logic and structures. There is no VB-equivalent of the "DoCmd" construct with all its database-specific actions.

Given all that, your question about how to
Code:
stLinkCriteria = "[Lab Number]=" & Me![Lab Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria
in VB really means that you need an understanding of how VB forms are constructed and instantiated; how controls are placed on those forms; and how SQL statements are constructed and processed to retrieve information and display it in a control.

The answers that you received from the other posters essentially told you how to run Access from VB, which looked like the question you were asking. Your interest seems to be "how to communicate with the JET Engine from VB" and that's a very different creature.
 
Kathy, these three samples from Planet Source Code may help you.
[ul]
[li] Print & Preview MS Access Report In VB [/li]
[li] Print an Access Report / Run a SQL Action [/li]
[li] Printing a Microsoft Access Report from Visual Bas [/li]
[/ul]
These are all samples use Access. If you need to use Access only as back end and VB front. You can utilize the "datareports" that comes with VB6, more or less similar to Access reports.
You will find more samples there if you search with keywords.

________________________________________
Zameer Abdulla
Visit Me
There is only one perfect child in this world. Every mother has it.
 
Thanks all. This is exactly what I needed!

kathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top