473,473 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Invalid use of Null

105 New Member
Hi all!

I have a form with a combo box. If the user forgets to select something from the combo box and hits the "Save" command button, an error pops up that says Run-time error '94': Invalid use of Null. What am i doing wrong? Here's my code...

Expand|Select|Wrap|Line Numbers
  1. Dim Opportunity As String
  2. Dim message As String
  3.  
  4. cmbTeaching.SetFocus
  5. Opportunity = cmbTeaching.Value
  6.  
  7. 'Check if a teaching opportunity was selected; if not, ask the user to select one
  8. If cmbTeaching = "" Then
  9.     MsgBox ("Please select an Opportunity")
  10.     Exit Sub
  11. End If
Thanks in advance for your help!!!
Feb 27 '08 #1
7 1956
JKing
1,206 Recognized Expert Top Contributor
Hi all!

I have a form with a combo box. If the user forgets to select something from the combo box and hits the "Save" command button, an error pops up that says Run-time error '94': Invalid use of Null. What am i doing wrong? Here's my code...

Expand|Select|Wrap|Line Numbers
  1. Dim Opportunity As String
  2. Dim message As String
  3.  
  4. cmbTeaching.SetFocus
  5. Opportunity = cmbTeaching.Value
  6.  
  7. 'Check if a teaching opportunity was selected; if not, ask the user to select one
  8. If cmbTeaching = "" Then
  9.     MsgBox ("Please select an Opportunity")
  10.     Exit Sub
  11. End If
Thanks in advance for your help!!!
Hi there,

You were trying to set Opportunity to the value of a combobox before validating the combobox. You need to check for null first and then set Opportunity.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim Opportunity As String
  4.  
  5. Dim message As String
  6.  
  7. Me.cmbTeaching.SetFocus
  8.  
  9. 'Check if a teaching opportunity was selected; if not, ask the user to select one
  10.  
  11. If IsNull(Me.cmbTeaching) Then
  12.  
  13.     MsgBox ("Please select an Opportunity")
  14.  
  15.     Exit Sub
  16.  
  17. Else
  18.  
  19.     Opportunity = Me.cmbTeaching.Value
  20.  
  21. End If
  22.  
Feb 27 '08 #2
jmarcrum
105 New Member
Hi there,

You were trying to set Opportunity to the value of a combobox before validating the combobox. You need to check for null first and then set Opportunity.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim Opportunity As String
  4.  
  5. Dim message As String
  6.  
  7. Me.cmbTeaching.SetFocus
  8.  
  9. 'Check if a teaching opportunity was selected; if not, ask the user to select one
  10.  
  11. If IsNull(Me.cmbTeaching) Then
  12.  
  13.     MsgBox ("Please select an Opportunity")
  14.  
  15.     Exit Sub
  16.  
  17. Else
  18.  
  19.     Opportunity = Me.cmbTeaching.Value
  20.  
  21. End If
  22.  
I changed my code to that and it threw a different error. "the expression On Click you entered as the event property setting produced the following error: Method or data member not found.

Visual Basic for Applications (VBA) encountered a problem while attempting to access a property or method. The problem may be one of the following:
A reference is missing.
For help restoring missing references, see the Microsoft Knowledge Base article 283806.
An Expression is misspelled.
Check all expressions used in event properties for correct spelling.
A user-defined function is declared as a sub or as a private function in a module.
Expressions can resolve a user-defined function only if the function is declared as one of the following:
A public function in a module
A public or private function in a code module of the current form or report
Security in Access is set to Medium or High and the Microsoft Jet 4.0 SP8 update is not installed.
A more recent verion of Jet 4.0 must be installed for Access to function properly when security is set to Medium or High. To obtain the latest version of Microsoft Jet, go to Windows Update.
Feb 27 '08 #3
jmarcrum
105 New Member
does anyone know how to fix this?
Feb 27 '08 #4
JKing
1,206 Recognized Expert Top Contributor
I think that maybe a copy and paste error on my part.

I had made a little mock up button on a form to test your scenario and ensure accuracy of my response. However upon copy and pasting to the forum I accidentally included the "Private Sub Command0_Click".

Try removing the "Private Sub Command0_Click" and you should be fine. If not post the code you are now using.
Feb 27 '08 #5
jmarcrum
105 New Member
I think that maybe a copy and paste error on my part.

I had made a little mock up button on a form to test your scenario and ensure accuracy of my response. However upon copy and pasting to the forum I accidentally included the "Private Sub Command0_Click".

Try removing the "Private Sub Command0_Click" and you should be fine. If not post the code you are now using.
I didn't paste that part of the code. The error is coming from the code you wrote... Here's what I have now....

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSaveClose_Click()
  2. '*************************************************************'
  3. 'Author:                         '
  4. 'Date: 2/26/2008                                              '
  5. 'Desc: Assign a new Opportunity to the selected member        '
  6. 'Modifications:                                               '
  7. '                                                             '
  8. '*************************************************************'
  9. Dim Opportunity As String
  10. Dim message As String
  11.  
  12. Me.cmbTeaching.SetFocus
  13.  
  14. 'Check if a teaching opportunity was selected; if not, ask the user to select one 
  15. If IsNull(Me.cmbTeaching) Then 
  16.     MsgBox ("Please select an Opportunity")
  17.     Exit Sub
  18. Else
  19.     Opportunity = Me.cmbTeaching.Value
  20. End If
  21.  
  22. 'Make sure the Opportunity does not already exsist
  23. If OpportunityExists(Me.cmbTeaching.Value, Forms!frmMenMemberInfo!MemberID.Value) Then
  24.     MsgBox "This Opportunity is already assigned to this member."
  25.     Exit Sub
  26. End If
  27.  
  28. 'Save the Record
  29. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  30.  
  31. 'Requery the form
  32. Forms!frmMenMemberInfo!frmMenTeaching.Form.RecordSource = "SELECT tblMenDuties.Member, tblMenDuties.MenTeachingOpportunityID, tblMenTeachingOpportunities.MenTeachingOpportunity, tblMenDuties.MemberID FROM tblMenDuties INNER JOIN tblMenTeachingOpportunities ON tblMenDuties.MenTeachingOpportunityID = tblMenTeachingOpportunities.MenTeachingOpportunityID WHERE (((tblMenDuties.Member)=[Forms]![frmMenMemberInfo]![Member]));"
  33.  
  34. DoCmd.Close
  35.  
  36. Exit Sub
  37.  
  38. End Sub
  39.  
  40. Public Function OpportunityExists(MenTeachingOpportunityID As Integer, MemberID As Integer) As Boolean
  41. '*************************************************************'
  42. 'Author:                                '
  43. 'Date: 2/26/2008                                              '
  44. 'Desc: Returns True if Opportunity passed in exists in        '
  45. '      tblMenDuties; False otherwise                          '
  46. 'Modifications:                                               '
  47. '                                                             '
  48. '*************************************************************'
  49. Dim strSQL As String
  50. Dim dbs_curr As Database
  51. Dim record As Recordset
  52.  
  53. Set dbs_curr = CurrentDb
  54.  
  55. strSQL = "SELECT tblMenDuties.* FROM tblMenDuties WHERE (((tblMenDuties.MenTeachingOpportunityID)=" & MenTeachingOpportunityID & ") AND ((tblMenDuties.MemberID)=" & MemberID & "));"
  56. Set record = dbs_curr.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges, dbOptimistic)
  57.  
  58. If Not record.EOF Then
  59.     OpportunityExists = True
  60. Else
  61.     OpportunityExists = False
  62. End If
  63.  
  64. End Function
Feb 27 '08 #6
Megalog
378 Recognized Expert Contributor
Maybe it's because 'Opportunity' is supposed to be a string, yet you're assigning an integer to it? Although I would imagine the error you receive would be about a data type mismatch. You could get rid of that alltogether and use:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'Check if a teaching opportunity was selected; if not, ask the user to select one 
  3. If IsNull(Me.cmbTeaching) Then 
  4.     MsgBox ("Please select an Opportunity")
  5.     Exit Sub
  6. Else
  7.     'Make sure the Opportunity does not already exsist
  8.     If OpportunityExists(Me.cmbTeaching.Value, Forms!frmMenMemberInfo!MemberID.Value) Then
  9.         MsgBox "This Opportunity is already assigned to this member."
  10.         Exit Sub
  11.     End If
  12. End If
  13.  
  14.  
Feb 27 '08 #7
jmarcrum
105 New Member
Maybe it's because 'Opportunity' is supposed to be a string, yet you're assigning an integer to it? Although I would imagine the error you receive would be about a data type mismatch. You could get rid of that alltogether and use:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'Check if a teaching opportunity was selected; if not, ask the user to select one 
  3. If IsNull(Me.cmbTeaching) Then 
  4.     MsgBox ("Please select an Opportunity")
  5.     Exit Sub
  6. Else
  7.     'Make sure the Opportunity does not already exsist
  8.     If OpportunityExists(Me.cmbTeaching.Value, Forms!frmMenMemberInfo!MemberID.Value) Then
  9.         MsgBox "This Opportunity is already assigned to this member."
  10.         Exit Sub
  11.     End If
  12. End If
  13.  
  14.  
YOU ARE A GENIOUS!!!!

WORKED LIKE A CHARM!!!

Thanks for yall's help! That was takin me forever!!
Feb 27 '08 #8

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

Similar topics

6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
1
by: Patrick Dunnigan | last post by:
Hi, I am attempting a bulk copy from a c program into SQL Server 2000 using DBLib in freeTDS 0.63 RC11 (gcc 3.4.3, RH 9). I am getting an error message that I cannot find any documentation on. ...
2
by: headware | last post by:
I'm getting a weird problem in an Access query. I have a table that contains a field calle F1 that's a 2 character text field. The first character is always a number. What I'd like to do is find...
3
by: Frank Perry | last post by:
Howdy, I'm trying to write data out the com port. I have taken the code from the sample on the MSDN Library CD and used the parts that seem relevant. I can open the com port with CreateFile...
0
by: Jerry | last post by:
Below is ALL the code for all the databases... Here's the problem: I callup the aspx file in IE and the form comes up just fine. When I select a person to update, I get the subject error. ...
15
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed...
9
by: Jamie | last post by:
I am receiving an Invalid ViewState error after posting back to the same page twice. Consistently the error occurs after the second postback and not after the first. I have looked into creating...
6
by: KWienhold | last post by:
I'm currently working on a project in C# (VS 2003 SP1, .Net 1.1) that utilizes IStream/IStorage COM-Elements. Up to now I have gotten everything to work to my satisfaction, but now I have come...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
3
by: rando1000 | last post by:
I'm pulling data from a field on a form, evaluating whether or not it's null, then calculating based on the data in the field. Here's my code for evaluating the field: intAdvanced = IIf(Not...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.