Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load VB form via string variable

Status
Not open for further replies.

PhillCart

Technical User
Joined
Sep 4, 2001
Messages
4
Location
AU
Hi

I'm hoping that someone can give me some advice on a problem I have been presented with.

We have a VB5 application that has about 11-12 different data entry forms. When the application starts the user is presented with a list of marketing campaign codes. They select one of these codes which then loads the form related to that campaign and they do the data entry.

The problem I have is that marketing create a number of campaign codes that use the same form. We have about 35 codes in total.

I have setup a table in the database that provides the relationship between the form and the campaign code. How do I go about loading the specified form from a string variable? Is it possible?

I have explored using collection and object variables, but these all seem to require the actual form object as a parameter instead of just the name.

Hope someone can help.

Thanks
Phill
 
I would jist use a Select Case structure
Code:
Select Case Lcase(dbFormName)
Case "form1"
    .....
Case "form2"
    .....
Case Else
    MsgBox "Form=" & dbFormName & " does not exist."
End Select
Compare Code (Text)
Generate Sort in VB or VBScript
 
I already have a Select Case structure

It looks somewhat like this
Code:
Select Case intCampaignCell
  Case 345, 348, 367
    Set frmNew = New frmDirectMail
  Case 389, 392, 398, 412
    Set frmNew = New frmRetention
  ... Case repeated about 10 times ...
End Select

frmNew.show

What I would like to have is the name of the form in the database and then load the appropriate form based on the selected campaign code.

eg: User selects campaign 345 - this is working
results in SQL being executed to return formname - this is working
assign returned formname to variable - this is working
load form - this does not work B-(



 
Here's a function that returns the apprpriate form, given it's name:
[tt]
Public Function FormByName(strForm) As Form
Dim myForm As Form

' Check to see if form is already loaded
For Each myForm In Forms
If myForm.Name = strForm Then Exit For
Next

' Load named form if not already loaded
On Error GoTo BadForm
If myForm Is Nothing Then Set myForm = Forms.Add(strForm)
On Error GoTo 0

Set FormByName = myForm
Exit Function

BadForm:
If Err.Number = 424 Then Call Err.Raise(vbObjectError + 424, "FormByName", strForm + ": no such form exists in the project", "", 0)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top