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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox Peculiarities 1

Status
Not open for further replies.

rutkus

Programmer
Aug 28, 2001
41
0
0
US
I'm having some problems setting little internal control type procedures for a textbox in Access.

I have a textbox that is ONLY visible if a certain date is entered in another textbox on the same form, I need this textbox to be required when its visible. (Ive asked this question before). So far this is my code:

BeforeUpdate event:
If IsNull(Me.Processing_Comments.Value) Then
MsgBox ("Please Explain Yourself")
End If

This works perfectly if you enter text and then delete it. BUT If you hit tab without entering anything or get the msgbox hit ok and then hit tab, it lets you leave, which is exactly what I cant have happen. Is this a problem with isnull?? beforeupdate event?? or how im wording it?? It seems like it should work.


Please help,
HI-Priest
 
Try this:


If IsNull(Me.Processing_Comments.Value)Or (Me.Processing_Comments.value = "") Then
MsgBox ("Please Explain Yourself")
End If


Hope that helps.

Bob
 
Hi!

Try this code in the Exit event procedure:

If IsNull(Me!Processing_Comments.Text) = True Then
Call MsgBox("This field is required! " & _
"You must enter data!")
Cancel = -1
End If

This should catch all the situations you need.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks Jebry that worked perfectly.

I have another question based on an error that ive received a couple of times. When I write this type of line in textbox1 BeforeUpdate event:

Me.textbox2.Text = ""

I get error number 2115 which states:

The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Access from saving the data in the field.

What would cause this? and is there any way of getting around it??

Basically I need a textbox to be blank if another textbox is filled with something. So lets say textbox1 says an invoice is being processed, but if the user enters a date for textbox2 then the invoice isnt being processed anymore and that textbox needs to be cleared. Should I try a different event?? or is there a better way of accomplishing this??

Thanks
HI-Priest
 
Hi!

It sounds like text box 1 holds status information. When a date is set in text box 2, instead of clearing text box 1, set its value to complete. If you have a status field, it is usually best to not allow a zero length string.

If I am way off base as to what your question concerns, let me know.

hth Jeff Bridgham
bridgham@purdue.edu
 
Hey Jebry,

While yes, this textbox holds a status, my real concern is with the general concept, itself.

I understand why and how you cant reference a textbox unless it has focus, but the error comes when im clearing a textbox, after ive given it the focus. (in the beforeupdate event of a different textbox)

I hope that makes sense.


Thank you
HI-Priest
 
Hi!

Without looking at the database, I can only guess at the problem. But it sounds to me like the field that is the control source of the text box is set to not allow zero length strings. As per my last source, I think that is okay, just set the text box to some value instead of setting it to "". (I recommended complete) Note, if you use Me.textbox2.Value instead of .Text, you will not need to set the focus to the text box first.

hth Jeff Bridgham
bridgham@purdue.edu
 
I'm getting the same error. I dont really think it has to do with the length of the message entered. Basically in my program, I have a combobox that drops down and a user selects one of the values. OnClick I have it set the focus on a text box and fill it with a string that I obtained from a query based on the combobox entry. It then gives me this same error. Here is my code:

Private Sub WorkOrder_Click()

Call adhCtlTagPutItem(WorkOrder, "WorkOrder", WorkOrder.Text)

Dim db As Database
Dim size As String
Dim RNSize As TextBox

Set RNSize = RunSize
Set db = CurrentDb()

Dim rstWorkOrders As Recordset
Set rstWorkOrders = db.OpenRecordset("tblWorkOrders")
With rstWorkOrders
.MoveFirst
While rstWorkOrders(&quot;WorkOrder&quot;) <> adhCtlTagGetItem(WorkOrder, &quot;WorkOrder&quot;) Or .EOF
.MoveNext
Wend
If rstWorkOrders(&quot;WorkOrder&quot;) = adhCtlTagGetItem(WorkOrder, &quot;WorkOrder&quot;) Then
size = rstWorkOrders(&quot;RunSize&quot;)
End If
.Close
End With

RNSize.SetFocus
RNSize.Text = &quot;&quot; 'this is where the error is
RNSize.Text = size 'if I remove prev line, error is
' still there

WorkOrder.SetFocus

End Sub


If anyone can help I would really appreciate. I did basically the same thing in another program and it worked fine.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top