runtime error 94 invalid use of null (1 Viewer)

GRM-kenyette

Miss Kenyette
Local time
Today, 11:48
Joined
Mar 10, 2005
Messages
15
combobox help

hi all
i created a form from a table with 3 columns . I have a combo box on my form that is populated from column 1, and a textbox that is populated from column 2 when you choose a record from the combobox but the third textbox keeps generating an error - runtime error 94 invalid use of a null

here is the code im using

Private Sub cboAcctName_Click()
Dim strPopulateTextbox As String
Dim strPopulateTextbox2 As String

lblAcctName.Caption = cboAcctName.SelText

'populates the account number textbox with the chosen account name
strPopulateTextbox = cboAcctName.Column(1)
txtAcctNumber.Value = strPopulateTextbox

'populates the phonenumber as well
strPopulateTextbox2 = 0
strPopulateTextbox2 = cboAcctName.Column(2)
PHONENUMBER.Value = strPopulateTextbox2
End Sub

any help is greatly appreciated
thankz
 
Last edited:

modest

Registered User.
Local time
Today, 11:48
Joined
Jan 4, 2005
Messages
1,220
Sorry I can't look at code as text.

Code:
Private Sub cboAcctName_Click()
    lblAcctName.Caption = cboAcctName.SelText
  'populates the account number textbox with the chosen account name
    Dim strPopulateTextbox As String
    strPopulateTextbox = cboAcctName.Column(1)
    txtAcctNumber.Value = strPopulateTextbox

  'populates the phonenumber as well
    Dim strPopulateTextbox2 As String
    strPopulateTextbox2 = 0
    strPopulateTextbox2 = cboAcctName.Column(2)
    PHONENUMBER.Value = strPopulateTextbox2
End Sub

also this is cluttered code, so before I look at this I will tell you that you should declare your variables in one place.

Code:
Private Sub cboAcctName_Click()
    Dim strPopulateTextbox As String
    Dim strPopulateTextbox2 As String

    lblAcctName.Caption = cboAcctName.SelText

[COLOR=Green]  'populates the account number textbox with the chosen account name[/COLOR]
    strPopulateTextbox = cboAcctName.Column(1)
    txtAcctNumber.Value = strPopulateTextbox

 [COLOR=Green] 'populates the phonenumber as well[/COLOR]
    strPopulateTextbox2 = 0
    strPopulateTextbox2 = cboAcctName.Column(2)
    PHONENUMBER.Value = strPopulateTextbox2
End Sub

Now it's ready for people to look at.
 

modest

Registered User.
Local time
Today, 11:48
Joined
Jan 4, 2005
Messages
1,220
Because I had to make your code presentable, I'll let someone else handle this-doesn't seem that hard. I don't think this will make any difference, but try capturing the values before setting your controls.

Code:
Private Sub cboAcctName_Click()
    Dim strPopulateTextbox As String
    Dim strPopulateTextbox2 As String

    lblAcctName.Caption = cboAcctName.SelText

    strPopulateTextbox = cboAcctName.Column(1)
    strPopulateTextbox2 = cboAcctName.Column(2)

  [COLOR=Green]'populates the account number textbox with the chosen account name[/COLOR]
    txtAcctNumber.Value = strPopulateTextbox

  [COLOR=Green]'populates the phonenumber as well[/COLOR]
    strPopulateTextbox2 = 0
    PHONENUMBER.Value = strPopulateTextbox2
End Sub
 

GRM-kenyette

Miss Kenyette
Local time
Today, 11:48
Joined
Mar 10, 2005
Messages
15
combobox help

thanks for the tips but the problem is there

how to do I declared the variable if thats the problem if the record is a phone number
 

FoFa

Registered User.
Local time
Today, 10:48
Joined
Jan 29, 2003
Messages
3,672
This Code:
Code:
   strPopulateTextbox2 = cboAcctName.Column(2)

  'populates the account number textbox with the chosen account name
    txtAcctNumber.Value = strPopulateTextbox

  'populates the phonenumber as well
    strPopulateTextbox2 = 0
    PHONENUMBER.Value = strPopulateTextbox2

Is no good, it always resets strPopulateTextbox2 to 0, your original code did not do that.
What your error menas is you have a NULL value, and you are doing something with it that is not allowed with a NULL value.
I suspect this line: lblAcctName.Caption = cboAcctName.SelText
try this instead:
DIM WorkText as string
IF ISNULL(cboAcctName.SelText) then
lblAcctName.Caption = ""
ELSE
lblAcctName.Caption = cboAcctName.SelText
END IF

If that does not fix it, try the same thing on the other assignments.
 

modest

Registered User.
Local time
Today, 11:48
Joined
Jan 4, 2005
Messages
1,220
agh.. does no one ever use the debug/watch/locals windows anymore?? I need to write a tutorial on how to do that.

lblAcctName.Caption = cboAcctName.SelText
What is this actually doing. Why do you need it?


And.. if the first textbox can be populated the second one can as well using the isnull as fofo described. However, I don't agree with his/her statement on how to fix it. Because even when you know there's data there... if the null error comes up, your program will still work and you will think everything's fine.

You should use it when you know everything is working as should, in case you get to a field in your table that wasn't filled in.
 

GRM-kenyette

Miss Kenyette
Local time
Today, 11:48
Joined
Mar 10, 2005
Messages
15
Please Help

ive tried all the tips but to know avail can anybody show me where im going wrong please

the code
Private Sub cboAcctName_Click()

Dim strPopulateTextbox As String 'Declares a string variable
Dim strPopulateTextbox2 As String

strPopulateTextbox = cboAcctName.Column(1)
lblAcctName.Caption = cboAcctName.SelText
txtAcctNumber.Value = strPopulateTextbox

'------------------everything working above -----------


THIS CODE HAS INVALID USE OF NULL AS THE ERROR
strPopulateTextbox = cboAcctName.Column(2)
strPopulateTextbox2 = ""
PHONENUMBER.Value = strPopulateTextbox2

THANZS
End Sub
 

modest

Registered User.
Local time
Today, 11:48
Joined
Jan 4, 2005
Messages
1,220
Are you sure you set your combobox to hold 3 columns? Go back and check to make sure...attach your db so I can look at it.. but do it soon, because I have to leave shortly.
 

modest

Registered User.
Local time
Today, 11:48
Joined
Jan 4, 2005
Messages
1,220
When you reply to a post, scroll down a little past the submit button. You'll see an Additional Options table.

If you look into it, you'll see a Manage Attachments button. If you click that you'll get a pop-up and I'm hoping you can find your way from there.
 

GRM-kenyette

Miss Kenyette
Local time
Today, 11:48
Joined
Mar 10, 2005
Messages
15
New Error

Thanksz For The Help But Im Getting A New Error That States That
The Field Cannot Be A Zero Length String
IT WONT LET ME ATTACH THE DB

--------------------------------------
THANKS FOR ALL THE HELP ADDING THE 3RD COLUMN WORKED
 
Last edited:

FoFa

Registered User.
Local time
Today, 10:48
Joined
Jan 29, 2003
Messages
3,672
Zero length string would be a limit on your table field.
Code:
 strPopulateTextbox = cboAcctName.Column(2)
strPopulateTextbox2 = ""
PHONENUMBER.Value = strPopulateTextbox2

The second line is setting strPopulateTextbox2 to a zero length string
Then you assign that to PHONENUMBER
 

modest

Registered User.
Local time
Today, 11:48
Joined
Jan 4, 2005
Messages
1,220
Code:
strPopulateTextbox = cboAcctName.Column(2) [I]why do you do this if you never use strPopulateTextbox again[/I]
strPopulateTextbox[B]2[/B] = ""   [I]this is useless[/I]
PHONENUMBER.Value = strPopulateTextbox[B]2[/B]
make sure you spelled everythign correctly
 

timandy93

New member
Local time
Today, 16:48
Joined
Apr 30, 2011
Messages
1
I am having a little trouble myself with VB. Im new to it but I need to solve a problem that my daughter has on her database. She made a new function on VB for her book library database that calculates the number of school days between the due date of a book and the return date of her book which excludes holidays and weekends so that a fine can be worked out. Problem is that it works in her reports (when she tries to work out a fine on the actual report) but not on her subform, which gives her this message

"Error 94 (Invalid use of Null) in procedure CalcSchoolDays of Module modDateFunctions"


Another problem that she faces is that there seems to be something wrong with the function perhaps because the number of school days overdue is not accurate. I have attached a screen shot to show you the subform with errors in the "number of school days overdue column.
h-t-t-p:/-/-i-5-3.-t-in-ypi-c-.-c-o-m-/-rj-fk-9x-.p-n-g (just remove all the hyphens)

These are the holiday dates that need to be avoided:

Session,Term start,Term end
Autumn part one,2 Sept 2010,22 Oct 2010
Autumn Half term,week commencing 25 Oct 2010,week ending and including 31 Oct 2010
Autumn part two,1 Nov 2010,17 Dec 2010
Spring part one,5 Jan 2011,18 Feb 2011
Spring Half term,week commencing 21 Feb 2011,week ending and including 27 Feb 2011
Spring part two,28 Feb 2011,8 April 2011
Summer part one,27 April 2011,27 May 2011
Summer Half term,week commencing 30 May 2011,week ending and including 5 June 2011
Summer part two,6 June 2011,22 July 2011


School week is Monday to Friday inclusive



Here is the function she created:

Function CalcSchoolDays(StartDate, EndDate) As Integer

On Error GoTo CalcSchoolDays_Error

'Calculates the number of days between the dates
'Add one so all days are included
CalcSchoolDays = DateDiff("d", StartDate, EndDate) - _
(DateDiff("ww", StartDate, EndDate, 7) + _
DateDiff("ww", StartDate, EndDate, 1)) + 1
'Subtract the Holidays
CalcSchoolDays = CalcSchoolDays - DCount("*", "Term dates", "[Dates] between #" & StartDate & "# And #" & EndDate & "#")

CalcSchoolDays_Exit:

On Error Resume Next
Exit Function

CalcSchoolDays_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure CalcSchoolDays of Module modDateFunctions"
GoTo CalcSchoolDays_Exit

End Function


She need the solution by Monday morning if that is possible.

Thanks,
timandy93:)
 

Users who are viewing this thread

Top Bottom