Solved

PUBLIC

Posted on 1998-11-06
1
180 Views
Last Modified: 2010-04-30
I have a model I am programming.  It dynamically opens any database the user chooses and after they click on what fields they want, they will get a chart in VB as MSChart or if they choose they will get one In excel.  

I am using Dynamic SQL code to retrieve the data for the
charts.  I have this problem solved, the problem is, i have to write the same exact code in about 7 spots, for every command button, is there a way I can write the code once using a public function or declaring public?  This is the code:

Dim SQLSTR As String, CHAR
CHAR = ""
If sellist.ListCount > 0 Then
For i = 0 To sellist.ListCount - 1
selstr = "[" & sellist.List(i) & "]"
thestr = thestr & "," & selstr

Next
End If

If Mid(thestr, 1, 1) = "," Then
thestr = Mid(thestr, 2, Len(thestr))
End If



If sqlbox.Text <> "" Then
SQLSTR = "SELECT " & thestr & " FROM " & "[" & tablelist.Text & "]" & " WHERE " & sqlbox.Text
End If

If sqlbox.Text = "" Then
SQLSTR = "SELECT " & thestr & " FROM " & "[" & tablelist.Text & "]"
End If

If Len(File1.path) = 3 Then
path = Mid(File1.path, 1, 3)
Else:
path = File1.path & "\"
End If

for example, the user presses this button to show a database grid. I write the code in that button.  The user presses another button to generate a chart, I write the code in that button also, How do I write it one time?


Thanks
0
Comment
Question by:DAVIDH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
Poddy earned 70 total points
ID: 1443508
just put

public sub TheCode()

[....]

end Sub

around the code and put

TheCode into the command buttons
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question