Solved

PUBLIC

Posted on 1998-11-06
1
177 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
1 Comment
 
LVL 2

Accepted Solution

by:
Poddy earned 70 total points
Comment Utility
just put

public sub TheCode()

[....]

end Sub

around the code and put

TheCode into the command buttons
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now