Trouble with zero-length string error using OpenArgs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angi35
    New Member
    • Jan 2008
    • 55

    #1

    Trouble with zero-length string error using OpenArgs

    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:
    Code:
    Private Sub cmdButton_Click()
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "Add Job"
        DoCmd.OpenForm stDocName, , , stLinkCriteria, , , OpenArgs:=txtInfo1 & "|" & txtInfo2 & _
            "|" & txtInfo3
        
    End Sub
    Module:
    Code:
    Public Function ParseText(TextIn As String, x) As Variant
    On Error Resume Next
    Dim Var As Variant
    Var = Split(TextIn, "|", -1)
    ParseText = Var(x)
    
    End Function
    In FormB:
    Code:
    Private Sub Form_Load()
    
    If Not IsNull(Me.OpenArgs) Then
        Dim strText1 As String
        Dim strText2 As String
        Dim strText3 As String
    
        strText1 = ParseText(OpenArgs, 0)
        strText2 = ParseText(OpenArgs, 1)
        strText3 = ParseText(OpenArgs, 2)
        
        Me.txtFirst.DefaultValue = "=" & """" & strText1 & """"
        Me.txtSecond.DefaultValue = "=" & """" & strText2 & """"
        Me.txtThird.DefaultValue = "=" & """" & strText3 & """"
    
        
    End If
    
    End Sub
    Thanks for any help you can offer!
    Angi
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    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:

    Code:
    If  strText1 <> "" Then 
      Me.txtFirst.DefaultValue = "=" & """" & strText1 & """"
    End If
    Linq ;0)>

    Comment

    • angi35
      New Member
      • Jan 2008
      • 55

      #3
      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

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Glad we could help!

        Linq ;0)>

        Comment

        Working...