Connecting Tech Pros Worldwide Forums | Help | Site Map

Trouble with zero-length string error using OpenArgs

Member
 
Join Date: Jan 2008
Posts: 55
#1: Aug 8 '08
I'm having a zero-length string problem... Hoping someone can help. (This is in Access 2000.)

In FormA, I have a button that opens FormB with OpenArgs. In FormB, the OpenArgs are translated into default values for certain controls.

FormB is a continuous form. For this reason, I can't assign .Value -- it has to be .DefaultValue. Otherwise it changes the values in the first record in the form.

If any of the transferred controls in FormA has no data, then there's of course no data in the corresponding default value in FormB. Apparently Access is reading this as a 'zero-length string' in FormB, and it gives me an error message (Field tbl.fld cannot be a zero-length string) when I try to save the new record in FormB.

How do I get it to read Null values in FormA as Null in FormB? I haven't been able to figure it out.

Here's my code:

In FormA:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdButton_Click()
  2.  
  3.     Dim stDocName As String
  4.     Dim stLinkCriteria As String
  5.  
  6.     stDocName = "Add Job"
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria, , , OpenArgs:=txtInfo1 & "|" & txtInfo2 & _
  8.         "|" & txtInfo3
  9.  
  10. End Sub
Module:
Expand|Select|Wrap|Line Numbers
  1. Public Function ParseText(TextIn As String, x) As Variant
  2. On Error Resume Next
  3. Dim Var As Variant
  4. Var = Split(TextIn, "|", -1)
  5. ParseText = Var(x)
  6.  
  7. End Function
In FormB:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. If Not IsNull(Me.OpenArgs) Then
  4.     Dim strText1 As String
  5.     Dim strText2 As String
  6.     Dim strText3 As String
  7.  
  8.     strText1 = ParseText(OpenArgs, 0)
  9.     strText2 = ParseText(OpenArgs, 1)
  10.     strText3 = ParseText(OpenArgs, 2)
  11.  
  12.     Me.txtFirst.DefaultValue = "=" & """" & strText1 & """"
  13.     Me.txtSecond.DefaultValue = "=" & """" & strText2 & """"
  14.     Me.txtThird.DefaultValue = "=" & """" & strText3 & """"
  15.  
  16.  
  17. End If
  18.  
  19. End Sub
Thanks for any help you can offer!
Angi
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,997
#2: Aug 8 '08

re: Trouble with zero-length string error using OpenArgs


To be honest, I'm a little confused as to what's giving you the zero-length strings here, insteasd of nulls, and the form being continuous view is neither here nor there. But what you need to do, I guess, is to check before assigning your Default Values, something like this:

Expand|Select|Wrap|Line Numbers
  1. If  strText1 <> "" Then 
  2.   Me.txtFirst.DefaultValue = "=" & """" & strText1 & """"
  3. End If
  4.  
Linq ;0)>
Member
 
Join Date: Jan 2008
Posts: 55
#3: Aug 8 '08

re: Trouble with zero-length string error using OpenArgs


What a relief. It works. I figured it would be something like this, but the whole null/empty/zero-length string thing makes my head spin, and I just could not get Access to understand what I was trying to tell it. Really appreciate the help!

Angi
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,997
#4: Aug 8 '08

re: Trouble with zero-length string error using OpenArgs


Glad we could help!

Linq ;0)>
Reply