By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,392 Members | 1,576 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,392 IT Pros & Developers. It's quick & easy.

Trouble with zero-length string error using OpenArgs

P: 55
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
Aug 8 '08 #1
Share this Question
Share on Google+
3 Replies


missinglinq
Expert 2.5K+
P: 3,532
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)>
Aug 8 '08 #2

P: 55
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
Aug 8 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help!

Linq ;0)>
Aug 8 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.