473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Using a class module to create a user input box

I'm trying to setup an input box that will force the users of an Access DB to enter a (mandatory) comment before they update certain fields. The built-in 'InputBox' function only allows one line of 256 characters to be entered.

I'm looking for a larger, multiline textbox.

After some searching I came across this post:
http://www.dbforums.com/showthread.php?1675385-Make-input-form-bigger-to-allow-for-multi-line-text

This seems to do exactly what I want except for the fact it doesn't work... The problem: after adding all the code and looking for the post for additional instructions, I weeded out all error messages, but there is no pop-up box appearing.

My questions:
1) is anyone here familiar with the approach in the post I linked to? Or perhaps with this very code? If so, can you confirm this still works with access 2010?
2) Perhaps I'm making this too complicated and is there a better way to accomplish an improved / extended version of the default 'InputBox'

I have added a DB of the code to this post, exactly as copied from the instructions in the link.
Attached Files
File Type: zip UserInputFormTest.zip (38.8 KB, 76 views)
Mar 26 '15 #1

✓ answered by jforbes

I agree with Seth, there is no need to create a class and deal with properties.

To expand on what Seth has detailed, here is some code I copy and pasted together to accomplish what he's laid out. It allows you to supply the Prompt, Title and a Default Value for the TextBox:
Expand|Select|Wrap|Line Numbers
  1. ' Placed in a module
  2. Public gMultiLineInputBoxPrompt As String
  3. Public gMultiLineInputBoxTitle As String
  4. Public gMultiLineInputBoxValue As String
  5.  
  6. Public Function MultiLineInputBox(ByRef sPrompt As String, Optional sTitle As String = "MS Access", Optional sDefault As String = "")
  7.     gMultiLineInputBoxPrompt = sPrompt
  8.     gMultiLineInputBoxTitle = sTitle
  9.     gMultiLineInputBoxValue = sDefault
  10.     DoCmd.OpenForm FormName:="frmInputForm", WindowMode:=acDialog
  11.     MultiLineInputBox = gMultiLineInputBoxValue
  12. End Function
Expand|Select|Wrap|Line Numbers
  1. ' Placed in a Form
  2. Private Sub cmdCancel_Click()
  3.     gMultiLineInputBoxValue = ""
  4.     Docmd.Close
  5. End Sub
  6.  
  7. Private Sub cmdOK_Click()
  8.     gMultiLineInputBoxValue = Me.txtInput.Value
  9.     Docmd.Close
  10. End Sub
  11.  
  12. Private Sub Form_Load()
  13.     Me.Caption = gMultiLineInputBoxTitle
  14.     Me.lblInput.Caption = gMultiLineInputBoxPrompt
  15.     Me.txtInput.Value = gMultiLineInputBoxValue
  16. End Sub
Usage:
Expand|Select|Wrap|Line Numbers
  1. SomeVariable = MultiLineInputBox("What is your favorite color?", , "Red")
The trick really is to set the EnterKeyBehaviour Property of the TextBox to "New Line in Field", otherwise the Enter Key will move out of the TextBox and not create a new line.

4 1488
Seth Schrock
2,965 Expert 2GB
That is a very complicated way of doing things. All you need to do is create a form with the controls that you want. Then set the form's Modal and Pop Up properties to Yes. Create a global variable that will store the value that you enter. To open this form, use the following code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm FormName:="frmInputForm", WindowMode:=acDialog
In your form's OK button, assign the value that you have entered to the global variable and then close the form. Once the form has closed, then your code resumes at the next line after the line that opened the form. You can now reference your global variable to get the data that you entered.
Mar 26 '15 #2
One of the reasons this appealed to me, is that you can customize the Form each time you instantiate it. I have to use this popup for multiple fields.

If I understand your solution correctly, I would have to make a specific form for each situation, or precede each popup form with a popup message explaining to the user what to fill out.
Mar 26 '15 #3
jforbes
1,107 Expert 1GB
I agree with Seth, there is no need to create a class and deal with properties.

To expand on what Seth has detailed, here is some code I copy and pasted together to accomplish what he's laid out. It allows you to supply the Prompt, Title and a Default Value for the TextBox:
Expand|Select|Wrap|Line Numbers
  1. ' Placed in a module
  2. Public gMultiLineInputBoxPrompt As String
  3. Public gMultiLineInputBoxTitle As String
  4. Public gMultiLineInputBoxValue As String
  5.  
  6. Public Function MultiLineInputBox(ByRef sPrompt As String, Optional sTitle As String = "MS Access", Optional sDefault As String = "")
  7.     gMultiLineInputBoxPrompt = sPrompt
  8.     gMultiLineInputBoxTitle = sTitle
  9.     gMultiLineInputBoxValue = sDefault
  10.     DoCmd.OpenForm FormName:="frmInputForm", WindowMode:=acDialog
  11.     MultiLineInputBox = gMultiLineInputBoxValue
  12. End Function
Expand|Select|Wrap|Line Numbers
  1. ' Placed in a Form
  2. Private Sub cmdCancel_Click()
  3.     gMultiLineInputBoxValue = ""
  4.     Docmd.Close
  5. End Sub
  6.  
  7. Private Sub cmdOK_Click()
  8.     gMultiLineInputBoxValue = Me.txtInput.Value
  9.     Docmd.Close
  10. End Sub
  11.  
  12. Private Sub Form_Load()
  13.     Me.Caption = gMultiLineInputBoxTitle
  14.     Me.lblInput.Caption = gMultiLineInputBoxPrompt
  15.     Me.txtInput.Value = gMultiLineInputBoxValue
  16. End Sub
Usage:
Expand|Select|Wrap|Line Numbers
  1. SomeVariable = MultiLineInputBox("What is your favorite color?", , "Red")
The trick really is to set the EnterKeyBehaviour Property of the TextBox to "New Line in Field", otherwise the Enter Key will move out of the TextBox and not create a new line.
Mar 26 '15 #4
Seth, Jforbes,

Thanks both for your quick and accurate replies. With Jforbes addition, this will work for me!

In my implementation I made a small change: instead of using global variables I added the necessary variables to my collection of TempVars.
Mar 26 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: hokiegal99 | last post by:
I don't understand how to use a loop to keep track of user input. Could someone show me how to do what the program below does with a loop? Thnaks! ---------------------------- #Write a...
0
by: Paulers | last post by:
hello VB masters I have an issue that I am hoping you can help me with. I am creating an application that accepts user input via a richtextbox. the user can enter multiple entries and I need to...
6
evilmonkey
by: evilmonkey | last post by:
I am very new to programming as well as Java and this is my first post so please forgive me if this is not quite posted correctly. My Problem is that I have only been using scanner to get user input...
3
by: oozy | last post by:
Hi, I'm currently using Page.Form.DefaultButton = ChangePassword1.FindControl("xx").UniqueID to set my DefaultButtons in a form that has multiple wizards(each in it's own panel). I can...
4
by: bob1660 | last post by:
I am new to PHP and MYSQL. I have a Database table with 4 field. FirstName, LastName, DateofBirth and MemberNumber. I would like to have a form where a user can fill in the FirstName, LastName and...
6
by: =?Utf-8?B?TmFt?= | last post by:
Using Response.Redirect(“error.htm”) in the catch block of a try-catch statement, I am redirecting a page to a generic page if an error occurs in code-behind of the page. Since...
4
by: Steve Swift | last post by:
I have a page that accepts user input, including HTML. I would like to offer a preview of what the users HTML will look like, but I'd also like to avoid having to parse their HTML to ensure that it...
5
topher23
by: topher23 | last post by:
I've seen a lot of questions about how to make secure database passwords. I'm going to go over a method of encrypting a password using the MD5 encryption algorithm for maximum security. First,...
1
by: Melanie Kremer | last post by:
I have a report where the RecordSource is set based on user selections in several combo boxes. When I attempt to add print functionality, I can either print the report with the full RecordSource...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.