[Beginner]how retrieve VBA code from Wizard

peuplier

New member
Local time
Today, 21:15
Joined
Dec 11, 2008
Messages
5
Good morning
I need to know how to retrieve code from wizards. For example when you trigger Wizard to create sql queries, or a Forms, Reports, I think Access generate VBA code. Iam interresting how to retrieve this code. At first is it possible ? and if this is the case how to do ?
In my far experience in VB6, 10 years ago -time of dynosauraurus :D -, I recall we could retrieve the vb6 code, when launching a dao wizard. I don't know if this is possible today, with the new softwares nowadays

Thank for any help

Regards
 
Open the object that has VBA code, like a form or report, in design mode:

On the menu go to View > Code
 
Thanks HiTechCoach for your answer, however I would to retrieve vba code in any object created inside Access, even objects without vba. I tried to generate macro and vba code -as in Excel-, but it did not run as I want.
In Visual Basic, you had wizard, generated code, but you could access to this code.
For this purpose need I install other extension(s) ? Other(s) librair(ies) ?

Bye
 
atl + F11 usually opens the VBA editor, from there you can select any form or report or module with VBA in it.

as for retrieving VBA that doesn't exist? sorry, that's beyond my knowledge of access...

(edit: in the editor you can also add VBA to things that don't have it....)
 
peuplier.

... however I would to retrieve vba code in any object created inside Access, even objects without vba.
In Access, if the Objects does not have any VBA code, then there is no code to retrieve.

My guess is you are thinking like the way VB works when it create a form. You could look at the VB code use to generate the form (like a .frm file). Well Access does not work that way. Forms, reports, and queries are stored within system tables in Access, not as VBA code.

The closest thing will be to save the object as text using:

Access.Application.SaveAsText
 
You can use this to make a backup of your database objects also.

To restore an object use:

Access.Application.LoadFromText

For anyone interested, here is the code:

Code:
Sub DumpAllObjects(Optional strFilePath As String = "")

  Dim obj As AccessObject

  Dim strName As String

  Dim strDate As String

  

  On Error GoTo HandleError



  If strFilePath = "" Then

    strFilePath = Access.CurrentProject.Path  ' or any folder of your choice

  End If

  strDate = Format(Now(), "yyyymmddhhnnss")

  For Each obj In Access.Application.CurrentProject.AllForms

    Access.Application.SaveAsText acForm, obj.Name, strFilePath & "\" & strDate & obj.Name & ".txt"

  Next

  For Each obj In Access.Application.CurrentProject.AllReports

    Access.Application.SaveAsText acReport, obj.Name, strFilePath & "\" & strDate & obj.Name & ".txt"

  Next

  For Each obj In Access.Application.CurrentProject.AllMacros

    Access.Application.SaveAsText acMacro, obj.Name, strFilePath & "\" & strDate & obj.Name & ".txt"

  Next

  For Each obj In Access.Application.CurrentProject.AllModules

    Access.Application.SaveAsText acModule, obj.Name, strFilePath & "\" & strDate & obj.Name & ".txt"

  Next



ExitHere:

  Exit Sub

HandleError:

  Select Case VBA.Err.Number

    Case Else

      MsgBox Err.Number & " " & Err.Description

  End Select

  Resume Next

End Sub
 
Last edited:
Thx to you all who helped me. :)
peuplier.

In Access, if the Objects does not have any VBA code, then there is no code to retrieve.

Ok I understand now


My guess is you are thinking like the way VB works when it create a form.

Absolutly. This is what I wanted to do, I meaned that, the code generated for one object was necessary in VBA mode.

You could look at the VB code use to generate the form (like a .frm file).
As I understood, as there is no method to retrieve the code, you redirected the stream into .txt file. Interresting. In any way this is what I expected. I tried this code hours ago, and when it loads ole object, we cannot read


Well Access does not work that way. Forms, reports, and queries are stored within system tables in Access, not as VBA code.

The closest thing will be to save the object as text using:

Access.Application.SaveAsText
Thank you, I understood now. Do you think there is a possiblity to retrieve vba object into C# ?

Good bye :)
 

Users who are viewing this thread

Back
Top Bottom