VBA -> VB Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sirnoob
    New Member
    • Sep 2008
    • 6

    #1

    VBA -> VB Help

    hey all,
    i have the following code in VBA (access) and it works but i need to have similar code in Visual Basic (Visual Studio 2008) that does the same thing. so far the best i got was to have static links on the button. (don't have code on me atm so i can't see what i used)

    the goal of this code is to have 3 text fields to fill out the click on one of the buttons and it will open the correct PDF for that client given the ProjectID, Lastname and ClientID
    Code:
    Private Sub cmdSite_Click()
        Application.FollowHyperlink ("S:\ShedData\ShedOrders\~TEST\Quotes\" & Form_1.[ProjectNum] & " " & Form_1.[LastName] & "\Quotes\" & Form_1.[ProjectNum] & "-" & Form_1.[ClientID] & "-" & Form_1.[LastName] & "_SitePlan.pdf")
    End Sub

    Thanks for any help..
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    I am not sure of the exact issue you are having but the easiest way that I can see is to import ' microsoft internet controls ' from COM and then use something like -


    Code:
            Dim x As New SHDocVw.InternetExplorer()
    
            x.Navigate("http://microsoft.com")
    
            x.Visible = True

    I only have IE installed so am not sure if this will work with firefox.

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #3
      I did try to use ' System.Windows. Forms.WebBrowse r ' but I could not get it to show but that might have been me missing something :)

      Comment

      • sirnoob
        New Member
        • Sep 2008
        • 6

        #4
        sorry question was so bad but it was basicly trying to open a PDF depending on user input but i worked it out, code is below to explain it a bit better.

        1st one is in access and 2nd is in Visual studio 2008.
        Code:
        Private Sub cmdSite_Click()
        Application.FollowHyperlink ("C:\~TEST\Quotes\" & Form_1.[ProjectNum] & " " & Form_1.[LastName] & "\Quotes\" & Form_1.[ProjectNum] & "-" & Form_1.[ClientID] & "-" & Form_1.[LastName] & "_SitePlan.pdf")
        End Sub
        Code:
        Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
                Dim Client As String
                Dim Project As String
                Dim LName As String
                Project = Me.txtProject.Text
                Client = Me.txtClient.Text
                LName = Me.txtLast.Text
                Process.Start("C:\~Test\quotes\" & Project & " " & LName & "\quotes\" & Project & "-" & Client & "-" & LName & "_SitePlan.pdf")
            End Sub



        Now that i have got past that i need to make a listbox that gets its infomation from access. my problem is.. i can only have it display 1 row at a time but what i need is 2. but only using the projectnumber for referance (lastname is just for readability, cause having to remember 100's of numbers is just insane).

        need this in list box:
        ProjectNum - Name
        1 - bob
        2 - fred
        3 - dave

        what i have worked out is basicly just
        ProjectNum:
        1
        2
        3
        etc

        Or name:
        bob
        fred
        dave
        etc

        any help on this will be handy

        thanks.

        Comment

        • sirnoob
          New Member
          • Sep 2008
          • 6

          #5
          i ment Collum not row... doh.
          oh and btw the table also has a AutoNumberID what i need to refere to not the project number so the table is basicly:
          ID ProjectID Name
          1 133 bob

          i need the 133 - bob displayed and the 1 as the referance if u know what i mean.

          Comment

          • jg007
            Contributor
            • Mar 2008
            • 283

            #6
            looks like the listbox is probably best to use for this, although it is not exactly what you need the example I have added bellow should give you enough to work it out from

            it only works when multiselect is set to false but would be easy enough to ammend if you need to

            Code:
                Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
                    ListView1.View = View.Details
                    ListView1.FullRowSelect = True
                    ListView1.Columns.Add("Number")
                    ListView1.Columns.Add("Title")
            
                    For n = 1 To 4
                        Dim x = New ListViewItem
                        x.Text = "#" & n
                        x.SubItems.Add(" Test Item " & n)
                        ListView1.Items.Add(x)
                    Next n
            
                End Sub
            
                Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
                    If ListView1.SelectedIndices.Count = 0 Then Return
                    Dim lvi As ListViewItem = ListView1.SelectedItems(0)
                    MessageBox.Show(lvi.SubItems(1).Text)
            
            
            
            
                End Sub

            Comment

            • jg007
              Contributor
              • Mar 2008
              • 283

              #7
              I am using the second value of the item for the message box but you can use whichever substrings you want

              see if you can get the code working how you need and if not please post your code so that we can see where you are going wrong.

              Comment

              • sirnoob
                New Member
                • Sep 2008
                • 6

                #8
                I need somthing like the following (to get part a and b i only used to propities tab on the side) all this data will be saved in an Access Database.
                (IMG data is not the true data just random letters/numbers to help explain my point)


                Originally posted by jg007
                looks like the listbox is probably best to use for this, although it is not exactly what you need the example I have added bellow should give you enough to work it out from

                it only works when multiselect is set to false but would be easy enough to ammend if you need to

                Code:
                    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                
                        ListView1.View = View.Details
                        ListView1.FullRowSelect = True
                        ListView1.Columns.Add("Number")
                        ListView1.Columns.Add("Title")
                
                        For n = 1 To 4
                            Dim x = New ListViewItem
                            x.Text = "#" & n
                            x.SubItems.Add(" Test Item " & n)
                            ListView1.Items.Add(x)
                        Next n
                
                    End Sub
                
                    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
                        If ListView1.SelectedIndices.Count = 0 Then Return
                        Dim lvi As ListViewItem = ListView1.SelectedItems(0)
                        MessageBox.Show(lvi.SubItems(1).Text)
                
                
                
                
                    End Sub

                what is the listview1 mean? i guessed it was the name of a listbox but that gives alot of errors
                Last edited by sirnoob; Sep 14 '08, 04:58 PM. Reason: Adding Pic

                Comment

                • jg007
                  Contributor
                  • Mar 2008
                  • 283

                  #9
                  Sorry, that should say listVIEW not a listBOX <:)

                  Comment

                  • sirnoob
                    New Member
                    • Sep 2008
                    • 6

                    #10
                    Reference to a non-shared member requires an object refence

                    Comment

                    • jg007
                      Contributor
                      • Mar 2008
                      • 283

                      #11
                      where?, which line

                      this sounds like you are trying to access something directly when you need to create a new instance then work on it.

                      you might need to recheck your code.

                      Comment

                      Working...