?
Solved

vbOK

Posted on 1998-10-14
6
Medium Priority
?
442 Views
Last Modified: 2010-05-18
Hi,

I have a Inputbox.
I only want to use the OK button not the Cancel button.
Can I do this?
How do I do?
0
Comment
Question by:helenag
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Helicopter
ID: 1965338
You can't do this with a standard input box. You need to write your own (it's only a form with a text box and a couple of buttons after all)
0
 

Author Comment

by:helenag
ID: 1965339
OK.
0
 

Author Comment

by:helenag
ID: 1965340
If I want to do something like this, how do I do?
How do I code the VbCancel button?

If vbCancel= true then
strInput=strDefault
End if

?????
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 8

Expert Comment

by:Helicopter
ID: 1965341
Is this with the standard input box:

You need to return a value so call the inputbox function like:

Public Function testinput()
Dim x As String

x=InputBox ("do something")


End Function

If you press the cancel x will equal "" (unfortunately it also equals "" if you press OK with no text in the box)

So you could test for it by if x="" then strInput=strDefault.

(by the way are you using the default property of the input box, as in x = InputBox("do something", "prompt", "mydefault") If you use this then pressing OK returns the default message whereas cancel returns the empty string. Just a thought.



0
 

Author Comment

by:helenag
ID: 1965342
Ok,Thanks.
0
 
LVL 3

Accepted Solution

by:
tcurtin earned 20 total points
ID: 1965343
1. Use a small form as a dialog with borderstyle set to 'Dialog'.Turn off the 'RecordSelectors' and 'RecordNavigation' properties because I assume there is no bound recordsource.
Use a textbox or as many as needed. Set the form's KeyPreview property to 'Yes'. That way it will receive the keystrokes before the controls. Use the form's KeyPress event to enable the OK button:
Private Sub Form1_KeyPress(KeyAscii as Integer)
     Command1.enabled = true
End sub

2. If you are looking to enable the button if there is data in the textbox, use the change events to test for "":

Private Sub Text1_Change()
    If Text1.text <> "" then 'You can use the 'and' operator to
                             'test for all necessary textboxes.
        Command1.enabled = true
    Else
       Command1.enabled = false
    End if
End Sub
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

755 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