?
Solved

Custom Input Box

Posted on 2006-05-02
7
Medium Priority
?
1,802 Views
Last Modified: 2013-12-25

I have created a form that is essentially an input box.  It has a label, a text box and two buttons.  I have set it up so it resembles the rest of my application and thus cant use the standard inputbox control.  What I am trying to do is create a sub that loads the input box, changes the label (to a new dialogue) and then returns whatever is inputted into the text box as a result.  

For example... If the user double clicked on LblInput1 it would launch the new input box and then change the label to a new prompt for the user

If the no button is clicked the input box would unload, if the yes button is clicked whatever had been entered into the inputbox would be set to LblInput1.Caption

If the user double clicked in LblInput2 the same would happen but this time the same form would have to assign the contents of the textbox to this new LblInput2.Caption

Thanks in advance

Sy
0
Comment
Question by:sydodman
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 16587311
The below is Access code that does the same thing, you'll have to make it VB-friendly:

(from anywhere)
Global sReturnValue as String   '<--- Play with this to suit your needs..
(from the calling code)

Dim frm as Form

DoCmd.OpenForm "fdlg_your_dialog_form", acNormal
Set frm = Forms("fdlg_your_dialog_form")

sReturnValue  = ""
Call forms.fdlg_your_dialog_form.fn_update("Your Label Goes Here")

(from within your custom inbut box form)

Public sub fn_update(sLabel as String)

If Len(sLabel) > 0 then
   Me.SomeLabelControl.Caption = sLabel
else
   'Handle the instance of code opening this form with no label)
end if

end sub

Private Sub SomeButton_Click()

If Len(SomeTextBoxValue) > 0 then
   sReturnValue = SomeTextBoxValue
else
   'Handle the instance of user clicking 'Ok' button without adding text)
end if

UnLoad Me

End Sub

Hope this helps.
-Jim

0
 

Author Comment

by:sydodman
ID: 16587509
I think I understand the principle of the code but I am fairly new to visual basic and am not really sure how to make what you have given VB friendly...

For exmaple I cant get the docmd.openform to work, the set form returns a type mismatch and the call forms doesnt work either

Sorry
0
 
LVL 13

Expert Comment

by:rettiseert
ID: 16587518
This is almost the same:

In your inputbox form add this code:
-----------------------------------------------------

Private vRetVal As Variant

Public Function ShowWindow(strPrompt As String) As Variant
    Label1.Caption = strPrompt
    Me.Show vbModal
    ShowWindow = vRetVal
End Function

Private Sub cmdCancel_Click()
    'This is the evento for the cancel button
    vRetVal = False
    Me.Hide
End Sub

Private Sub cmdOK_Click()
    'This is the event for the OK button
    vRetVal = Text1.Text
    Me.Hide
End Sub


Now you can use ShowWindow every time you want to call your form, like this:
-----------------------------------------------------

Private Sub Label1_DblClick()

    Dim vRet As Variant
   
    vRet = Form1.ShowWindow("Write something")
    If Not vRet = False Then
        'OK, Change caption
        Label1.Caption = vRet
    Else
        'Cancel was press, Do nothing
    End If

End Sub
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Accepted Solution

by:
rettiseert earned 2000 total points
ID: 16587542
I forgot, add this line to the showwindow function:

Public Function ShowWindow(strPrompt As String) As Variant
    vRetVal = False '<----------------- add this line
    Label1.Caption = strPrompt
    Me.Show vbModal
    ShowWindow = vRetVal
End Function
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16587548
You can do something like...

' --------------------
'  Form1
' --------------------
Option Explicit

Private Sub Command1_Click()
    Dim answer As String
    Dim result As Boolean
    answer = Form2.ShowDialog("What is your name?", result)
    If result Then
        Label1.Caption = answer
    End If
End Sub

' --------------------
'  Form2
' --------------------
Option Explicit

Private answer As String
Private cancelled As Boolean

Public Function ShowDialog(ByVal prompt As String, ByRef result As Boolean) As String
    answer = ""
    Form2.Caption = prompt
    Form2.Show vbModal
    result = Not cancelled
    ShowDialog = answer
End Function

Private Sub cmdOk_Click()
    answer = Text1.Text
    cancelled = False
    Me.Hide
End Sub

Private Sub cmdCancel_Click()
    cancelled = True
    Me.Hide
End Sub
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16587555
Sorry rettiseert...didn't refresh.

My code is basically the same as yours.   =)
0
 

Author Comment

by:sydodman
ID: 16587777
Thanks very much,

A copy and paste answer!!!  Just the kind I like!!!

Thanks to everyone else also

Sy
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

750 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