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!

Updating a textbox's value

Status
Not open for further replies.

llafretaw

MIS
Oct 2, 2001
64
GB
Hi,
Im trying to change a textbox's value when the form loads, however I can't quite seem to get it working.
Basically the form is populated by a view that retrieves info from a back end table. If the date is equal to 01/01/1900 then I want the field to come up as blank.
I have tried doing the following in the Control Source property of the textbox:
IIf(actual_date]=01/01/1900,([txtactual__date], )

In addition I have tried the following code:

Private Sub Form_Load()
If txtactual.value = "01/01/1900" Then
Set txtactual.value = " "
End If
End Sub

But none of the above works, so I'm wondering am I forgetting something blantantly obviously? Any help would be appreciated

Thanks.
 
Try using the Text property instead of the Value:
Code:
Private Sub Form_Load()
  If txtActual.Text = "01/01/1900" Then
    Set txtActual.Text = " "
  End If
End Sub
 
I tried that, but it still didn't work, got an error about been unable to write to a read only property, but cheers anyway
 
VBA doesn't let you access the text property of a control if the control doesn't have focus. Also, you don't need to use the "Set" keyword when you're assigning string values.

Try this:

Private Sub Form_Load()
If txtActual.Text = "01/01/1900" Then
txtActual.SetFocus
txtActual.Text = " "
End If
End Sub

Is the textbox locked? If it is, you'll have to say txtActual.Locked = False before you try to set its text, and then when you're done, txtActual.Locked = True.
 
Hi,

I have tried the following:
Private Sub Form_Load()
txtactual.SetFocus
If txtactual.text = "01/01/1900" Then
txtactual.Locked = False
** txtactual.text = " " **
txtactual.Locked = True
End If
End Sub

But I get the error when it comes to the line with the ** and says that "This property is read only and cannot be set."
Is it anything to do with the fact the recordsource for this field is based on a view on the underlying table? If it is then i'll try getting around this problem someother way, but I appreciate the assistance...
 
You should double check to make sure the recordset that supplies the view isn't read-only. Some recordsets can't be edited because of the nature of the query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top