Connecting Tech Pros Worldwide Forums | Help | Site Map

VBA -> VB Help

Newbie
 
Join Date: Sep 2008
Posts: 6
#1: Sep 12 '08
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSite_Click()
  2.     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")
  3. End Sub 

Thanks for any help..

Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#2: Sep 12 '08

re: VBA -> VB Help


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 -


Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim x As New SHDocVw.InternetExplorer()
  3.  
  4.         x.Navigate("http://microsoft.com")
  5.  
  6.         x.Visible = True
  7.  
  8.  

I only have IE installed so am not sure if this will work with firefox.
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#3: Sep 12 '08

re: VBA -> VB Help


I did try to use ' System.Windows.Forms.WebBrowser ' but I could not get it to show but that might have been me missing something :)
Newbie
 
Join Date: Sep 2008
Posts: 6
#4: Sep 13 '08

re: VBA -> VB Help


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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSite_Click()
  2. Application.FollowHyperlink ("C:\~TEST\Quotes\" & Form_1.[ProjectNum] & " " & Form_1.[LastName] & "\Quotes\" & Form_1.[ProjectNum] & "-" & Form_1.[ClientID] & "-" & Form_1.[LastName] & "_SitePlan.pdf")
  3. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
  2.         Dim Client As String
  3.         Dim Project As String
  4.         Dim LName As String
  5.         Project = Me.txtProject.Text
  6.         Client = Me.txtClient.Text
  7.         LName = Me.txtLast.Text
  8.         Process.Start("C:\~Test\quotes\" & Project & " " & LName & "\quotes\" & Project & "-" & Client & "-" & LName & "_SitePlan.pdf")
  9.     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.
Newbie
 
Join Date: Sep 2008
Posts: 6
#5: Sep 14 '08

re: VBA -> VB Help


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.
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#6: Sep 14 '08

re: VBA -> VB Help


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

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.  
  4.         ListView1.View = View.Details
  5.         ListView1.FullRowSelect = True
  6.         ListView1.Columns.Add("Number")
  7.         ListView1.Columns.Add("Title")
  8.  
  9.         For n = 1 To 4
  10.             Dim x = New ListViewItem
  11.             x.Text = "#" & n
  12.             x.SubItems.Add(" Test Item " & n)
  13.             ListView1.Items.Add(x)
  14.         Next n
  15.  
  16.     End Sub
  17.  
  18.     Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
  19.         If ListView1.SelectedIndices.Count = 0 Then Return
  20.         Dim lvi As ListViewItem = ListView1.SelectedItems(0)
  21.         MessageBox.Show(lvi.SubItems(1).Text)
  22.  
  23.  
  24.  
  25.  
  26.     End Sub
  27.  
  28.  
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#7: Sep 14 '08

re: VBA -> VB Help


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.
Newbie
 
Join Date: Sep 2008
Posts: 6
#8: Sep 14 '08

re: VBA -> VB Help


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)



Quote:

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

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.  
  4.         ListView1.View = View.Details
  5.         ListView1.FullRowSelect = True
  6.         ListView1.Columns.Add("Number")
  7.         ListView1.Columns.Add("Title")
  8.  
  9.         For n = 1 To 4
  10.             Dim x = New ListViewItem
  11.             x.Text = "#" & n
  12.             x.SubItems.Add(" Test Item " & n)
  13.             ListView1.Items.Add(x)
  14.         Next n
  15.  
  16.     End Sub
  17.  
  18.     Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
  19.         If ListView1.SelectedIndices.Count = 0 Then Return
  20.         Dim lvi As ListViewItem = ListView1.SelectedItems(0)
  21.         MessageBox.Show(lvi.SubItems(1).Text)
  22.  
  23.  
  24.  
  25.  
  26.     End Sub
  27.  
  28.  


what is the listview1 mean? i guessed it was the name of a listbox but that gives alot of errors
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#9: Sep 14 '08

re: VBA -> VB Help


Sorry, that should say listVIEW not a listBOX <:)
Newbie
 
Join Date: Sep 2008
Posts: 6
#10: Sep 15 '08

re: VBA -> VB Help


Reference to a non-shared member requires an object refence
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#11: Sep 15 '08

re: VBA -> VB Help


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.
Reply