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!

Zero-Length String Error

Status
Not open for further replies.

mcongdon

Programmer
Mar 14, 2008
98
US
Hi Guys,
I have an Access form with a command button that will copy certain fields to the next record to be entered. The code for that button is:

Code:
Private Sub Command367_Click()
Me.BuySell.DefaultValue = "=" & Chr(34) & Me!BuySell.Value & Chr(34)
Me.TradeDate.DefaultValue = "=" & Chr(34) & Me!TradeDate.Value & Chr(34)
Me.SettlementDate.DefaultValue = "=" & Chr(34) & Me!SettlementDate.Value & Chr(34)
Me.CUSIPSymbol.DefaultValue = "=" & Chr(34) & Me!CUSIPSymbol.Value & Chr(34)
Me.SecurityDescription.DefaultValue = "=" & Chr(34) & Me!SecurityDescription.Value & Chr(34)
Me.Combo332.DefaultValue = "=" & Chr(34) & Me!Combo332.Value & Chr(34)
Me.Text362.DefaultValue = "=" & Chr(34) & Me!Text362.Value & Chr(34)
Me.Notes.DefaultValue = "=" & Chr(34) & Me!Notes.Value & Chr(34)
DoCmd.GoToRecord , , acNext
DoCmd.GoToControl "Account#"
End Sub

I have a problem with copying the field titled Notes. All the other ones being copied over are required to have data, therefore copying them to the next record is no problem. Because there aren't always notes, when the button is clicked and there are not notes, I get an error stating "Field 'tbl_Blotter.Notes' cannot be a zero-length string." Is there a way I can make my code copy it if it's there, but not if it isn't?

PS- I know some of my naming of fields and controls is bad form, but this is just an experiment at the moment. If I decide to include it in the real database, I will fix them.

Thanks!
 
if trim(Me!Notes.Value) <> "" then
Me.Notes.DefaultValue = "=" & Chr(34) & Me!Notes.Value & Chr(34)
end if
 
Replace this:
Me.Notes.DefaultValue = "=" & Chr(34) & Me!Notes.Value & Chr(34)
with this:
If Trim(Me!Notes.Value & "") <> "" Then
Me!Notes.DefaultValue = "=" & Chr(34) & Me!Notes.Value & Chr(34)
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or change the allow zero length property of the field on the table to yes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top