Make VB code work in MS Access 2000?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Make VB code work in MS Access 2000?

  1. #1
    Pihlis Guest

    Make VB code work in MS Access 2000?


    Dear Mr/Mrs/Ms, Linkoping, Sweden 160702

    I have written VB code in MS VB 6.0 and from there it can be run. Now I want
    to connect the code with MS Access 2000 and I have just found out that there
    I have to write the code in VBA. Now to my question. How, where and what
    in the VB code shall I change to get the VBA code to be executed. Below you
    can see some of the code:
    'start of code

    Option Explicit

    'subroutine for the button for choose of groundprofile (GrundProfil)
    Private Sub Grund_Click()
    Call Uppdatera(1) 'Grund.dot
    End Sub
    'subroutine for the button for choose of forthedayprofile (ForDagenProfil)
    Private Sub ForDagen_Click()
    Call Uppdatera(2) 'ForDagen.dot
    End Sub

    'subroutine for uppdateing of profile
    Private Sub Uppdatera(ByVal dotVal As Long)

    'declaration of Word
    Dim wd As Word.Application

    'declaration of document in Word
    Dim doc As Word.Document

    'declaration of field in Word there the text will be shown
    Dim ran As Range

    'declaration of bookmark in Word there the specific text shall stand
    Dim book As Bookmark

    On Error Resume Next

    Set wd = GetObject(, "Word.Application")

    If wd Is Nothing Then
    Set wd = CreateObject("Word.Application")

    If wd Is Nothing Then
    MsgBox ("MS Word is not installed")
    End If
    End If

    On Error GoTo 0

    Select Case dotVal

    Case Is = 1
    'path to folder there the groundprofile is
    Set doc = Documents.Add("\\combitechsystems.com\CS\Transfer\Linköping\"
    & _
    "Johanna Pihlström\Konsultprofil\Version1\Wordmallar\Grund.dot")
    'paste all the statments the shall be in this profile

    'name calls and writes in
    Set book = doc.Bookmarks.Item("namn")
    Set ran = book.Range
    ran.Text = namn.Text

    Grund.Caption = namn.Text
    'have deleted the rest because to fit more space in the post

    Case Is = 2
    'path to folder there the forthedayprofile is
    Set doc = Documents.Add("\\combitechsystems.com\CS\Transfer\Linköping\"
    & _
    "Johanna Pihlström\Konsultprofil\Version1\Wordmallar\ForDagen.dot")
    'paste all the statments the shall be in this profile

    'name calls and writes in
    Set book = doc.Bookmarks.Item("namn")
    Set ran = book.Range
    ran.Text = namn.Text

    ForDagen.Caption = namn.Text
    'have deleted the rest because to fit more space in the post
    End Select

    wd.Visible = True

    doc.Saved = True
    End Sub
    'end of code

    Hope you understand my woundering.

    Thanks in advance!

    Johanna Pihlström

  2. #2
    guanha Guest

    Re: Make VB code work in MS Access 2000?


    I'm not sure how you want to start the program in access.

    I assume that you want to execute the code in the buttons.

    This can be achieved by:

    - Setting the relevant references (to the VBA word library etc)
    - Creating an access form.
    - Creating two buttons, each having the relevant name
    - Including all your code in the form.

    Is this how you want to do it ?

    If not, give some hints, as to how youy want to do it !

    guanha

    "Pihlis" <i99jp@ryp.umu.se> wrote:
    >
    >Dear Mr/Mrs/Ms, Linkoping, Sweden 160702
    >
    >I have written VB code in MS VB 6.0 and from there it can be run. Now I

    want
    >to connect the code with MS Access 2000 and I have just found out that there
    >I have to write the code in VBA. Now to my question. How, where and what
    >in the VB code shall I change to get the VBA code to be executed. Below

    you
    >can see some of the code:
    >'start of code
    >
    >Option Explicit
    >
    >'subroutine for the button for choose of groundprofile (GrundProfil)
    >Private Sub Grund_Click()
    >Call Uppdatera(1) 'Grund.dot
    >End Sub
    >'subroutine for the button for choose of forthedayprofile (ForDagenProfil)
    >Private Sub ForDagen_Click()
    >Call Uppdatera(2) 'ForDagen.dot
    >End Sub
    >
    >'subroutine for uppdateing of profile
    >Private Sub Uppdatera(ByVal dotVal As Long)
    >
    >'declaration of Word
    >Dim wd As Word.Application
    >
    >'declaration of document in Word
    >Dim doc As Word.Document
    >
    >'declaration of field in Word there the text will be shown
    >Dim ran As Range
    >
    >'declaration of bookmark in Word there the specific text shall stand
    >Dim book As Bookmark
    >
    >On Error Resume Next
    >
    >Set wd = GetObject(, "Word.Application")
    >
    >If wd Is Nothing Then
    > Set wd = CreateObject("Word.Application")
    >
    > If wd Is Nothing Then
    > MsgBox ("MS Word is not installed")
    > End If
    >End If
    >
    >On Error GoTo 0
    >
    >Select Case dotVal
    >
    >Case Is = 1
    >'path to folder there the groundprofile is
    > Set doc = Documents.Add("\\combitechsystems.com\CS\Transfer\Linköping\"
    >& _
    > "Johanna Pihlström\Konsultprofil\Version1\Wordmallar\Grund.dot")
    > 'paste all the statments the shall be in this profile
    >
    > 'name calls and writes in
    > Set book = doc.Bookmarks.Item("namn")
    > Set ran = book.Range
    > ran.Text = namn.Text
    >
    > Grund.Caption = namn.Text
    > 'have deleted the rest because to fit more space in the post
    >
    >Case Is = 2
    >'path to folder there the forthedayprofile is
    > Set doc = Documents.Add("\\combitechsystems.com\CS\Transfer\Linköping\"
    >& _
    > "Johanna Pihlström\Konsultprofil\Version1\Wordmallar\ForDagen.dot")
    > 'paste all the statments the shall be in this profile
    >
    > 'name calls and writes in
    > Set book = doc.Bookmarks.Item("namn")
    > Set ran = book.Range
    > ran.Text = namn.Text
    >
    > ForDagen.Caption = namn.Text
    > 'have deleted the rest because to fit more space in the post
    >End Select
    >
    >wd.Visible = True
    >
    >doc.Saved = True
    >End Sub
    >'end of code
    >
    >Hope you understand my woundering.
    >
    >Thanks in advance!
    >
    >Johanna Pihlström



  3. #3
    Johanna Pihlström Guest

    Re: Make VB code work in MS Access 2000?


    Dear guanha,

    Yes, I want to compile the code in VBA successfully now I only get errors
    when paste the code into the MS Access 2000's VB Editor (Tools\Macro\VBE).
    When could compile and run the code from the VB 6.0 program whith no errors.
    I have now heared that the VB code is simular to the VBA code, but I do not
    know the differencies. Do you know where in my code there should be some
    changes or do you belive that I am doing wrong when writing in the code at
    MS Access 2000?
    See the code below.

    Thanks in advance!
    Johanna Pihlström (Pihlis)

    "guanha" <guanha@frisurf.no> wrote:
    >
    >I'm not sure how you want to start the program in access.
    >
    >I assume that you want to execute the code in the buttons.
    >
    >This can be achieved by:
    >
    >- Setting the relevant references (to the VBA word library etc)
    >- Creating an access form.
    >- Creating two buttons, each having the relevant name
    >- Including all your code in the form.
    >
    >Is this how you want to do it ?
    >
    >If not, give some hints, as to how youy want to do it !
    >
    >guanha
    >
    >"Pihlis" <i99jp@ryp.umu.se> wrote:
    >>
    >>Dear Mr/Mrs/Ms, Linkoping, Sweden 160702
    >>
    >>I have written VB code in MS VB 6.0 and from there it can be run. Now I

    >want
    >>to connect the code with MS Access 2000 and I have just found out that

    there
    >>I have to write the code in VBA. Now to my question. How, where and what
    >>in the VB code shall I change to get the VBA code to be executed. Below

    >you
    >>can see some of the code:
    >>'start of code
    >>
    >>Option Explicit
    >>
    >>'subroutine for the button for choose of groundprofile (GrundProfil)
    >>Private Sub Grund_Click()
    >>Call Uppdatera(1) 'Grund.dot
    >>End Sub
    >>'subroutine for the button for choose of forthedayprofile (ForDagenProfil)
    >>Private Sub ForDagen_Click()
    >>Call Uppdatera(2) 'ForDagen.dot
    >>End Sub
    >>
    >>'subroutine for uppdateing of profile
    >>Private Sub Uppdatera(ByVal dotVal As Long)
    >>
    >>'declaration of Word
    >>Dim wd As Word.Application
    >>
    >>'declaration of document in Word
    >>Dim doc As Word.Document
    >>
    >>'declaration of field in Word there the text will be shown
    >>Dim ran As Range
    >>
    >>'declaration of bookmark in Word there the specific text shall stand
    >>Dim book As Bookmark
    >>
    >>On Error Resume Next
    >>
    >>Set wd = GetObject(, "Word.Application")
    >>
    >>If wd Is Nothing Then
    >> Set wd = CreateObject("Word.Application")
    >>
    >> If wd Is Nothing Then
    >> MsgBox ("MS Word is not installed")
    >> End If
    >>End If
    >>
    >>On Error GoTo 0
    >>
    >>Select Case dotVal
    >>
    >>Case Is = 1
    >>'path to folder there the groundprofile is
    >> Set doc = Documents.Add("\\combitechsystems.com\CS\Transfer\Linköping\"
    >>& _
    >> "Johanna Pihlström\Konsultprofil\Version1\Wordmallar\Grund.dot")
    >> 'paste all the statments the shall be in this profile
    >>
    >> 'name calls and writes in
    >> Set book = doc.Bookmarks.Item("namn")
    >> Set ran = book.Range
    >> ran.Text = namn.Text
    >>
    >> Grund.Caption = namn.Text
    >> 'have deleted the rest because to fit more space in the post
    >>
    >>Case Is = 2
    >>'path to folder there the forthedayprofile is
    >> Set doc = Documents.Add("\\combitechsystems.com\CS\Transfer\Linköping\"
    >>& _
    >> "Johanna Pihlström\Konsultprofil\Version1\Wordmallar\ForDagen.dot")
    >> 'paste all the statments the shall be in this profile
    >>
    >> 'name calls and writes in
    >> Set book = doc.Bookmarks.Item("namn")
    >> Set ran = book.Range
    >> ran.Text = namn.Text
    >>
    >> ForDagen.Caption = namn.Text
    >> 'have deleted the rest because to fit more space in the post
    >>End Select
    >>
    >>wd.Visible = True
    >>
    >>doc.Saved = True
    >>End Sub
    >>'end of code
    >>
    >>Hope you understand my woundering.
    >>
    >>Thanks in advance!
    >>
    >>Johanna Pihlström

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center