PDA

View Full Version : Converting VB6 to VBA



FrymanTCU
04-07-2008, 01:41 PM
Okay have a huge module that checks the user's the legacy mainfram login status and I was curious how can I move this code to my Access file? I did not write this module, it was passed down from my predecessor, so I am not familar with all the refeneces and other high level coding he was capable of. But I know he used similar code in Access before, I just dont know how.

The 'Visual Basic for Applications' , 'Visual Basic runtime objects and procedures', 'Visual Basic objects and procedures' are the references that are not avaiable in VBA but does that matter?

This module is currently in VB6 and is called by a form that references an Excel sheet for particular identifiers that are sent, via SendKeys, to the mainfram system. Once the account is opened, the screen is scraped or modified depending on the code and then looped through the next account. But I want the code to grab a field in the Database to then scrape some data and return the value to Access.

Before I bore you with any more details, is this even worth pursuing by the begining? Just give me an idea of how hard this is on a difficulty scale of 1-5 where are we at?

Carl A
04-09-2008, 09:14 AM
FrymanTCU:
Depending on the module itself the level of difficulty could be any of the selections.
I have adapted many VB6 routines to work in VBA but not without a little :banghead: from time to time mainly from my ignorance of the nuances between VB6 and VBA, and after many hours of working on one I usually end up with a :doh:.

You as a developer should learn how adapt code from one platform to another as it just broadens your knowledge base and your salary.:thumb

Trevor
04-09-2008, 12:12 PM
Yes Fryman it is do-able (if thats even a real word ) :)
just remember little things like
vb: form.Show, form.hide
vba: form.Visible = True, form.visible = false
it will save you a lote of time :beerchug:
and Carl is right about adding to your "codeing toolbox" :-p

FrymanTCU
04-14-2008, 01:20 PM
I have two references in the VB6 code that I don't see in the VBA...

Visual Basic runtime objects and procedures
Visual Basic objects and procedures

I have transferred most of the modules I think I will need but the code keeps giving me a 'Variable not defined' error message and I have a feeling it is a missing reference.

Thanks,
Rich

Oorang
04-23-2008, 07:13 AM
Variable not defined is not a missing reference. It means you have Option Explicit declared at the top of the module. And the procedure uses a variable that was not declared using a Dim statement. To fix this just dim as a variant as undeclared variables are treated as variants anyway.

As a sidenote, after you have restored the original functionality, you might want to go back and see if a more defined type could be used instead. But that is more of a refactoring thing.