473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Error 13

Good Morning,

In my database I allow the user to move questions to a place in a sort order they determine it should be. To find out what number they want to move the question to I am using an input box.

I have the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim NewSort As Integer
  3.  
  4.     NewSort = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  5.  
The input box gives them the choices of OK and Cancel (which is what I want). The problem I have is if they click on Cancel I get a Mismatch error (13). I know I can trap this error, but didn't want to put a bandaid on the problem if there was a way to fix the problem.

Is trapping the error my best solution?

Thanks!
Lena
Nov 20 '06 #1
11 2169
willakawill
1,646 1GB
Good Morning,

In my database I allow the user to move questions to a place in a sort order they determine it should be. To find out what number they want to move the question to I am using an input box.

I have the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim NewSort As Integer
  3.  
  4.     NewSort = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  5.  
The input box gives them the choices of OK and Cancel (which is what I want). The problem I have is if they click on Cancel I get a Mismatch error (13). I know I can trap this error, but didn't want to put a bandaid on the problem if there was a way to fix the problem.

Is trapping the error my best solution?

Thanks!
Lena
Hi. It is not an error that you have to trap. The Inputbox returns a string. If the user presses Cancel it returns a zero length string "" which cannot be assigned to an integer. So do this
Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim NewSort As Integer
  3.     Dim stReturn As String
  4.  
  5.     stReturn = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  6.     If Len(stReturn) AND IsNumeric(stReturn) Then
  7.         NewSort = CInt(stReturn)
  8.     Else
  9.         MsgBox "Kind user please enter an integral numeric value"
  10.     End If
  11.  
Nov 20 '06 #2
Hi. It is not an error that you have to trap. The Inputbox returns a string. If the user presses Cancel it returns a zero length string "" which cannot be assigned to an integer. So do this
Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim NewSort As Integer
  3.     Dim stReturn As String
  4.  
  5.     stReturn = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  6.     If Len(stReturn) AND IsNumeric(stReturn) Then
  7.         NewSort = CInt(stReturn)
  8.     Else
  9.         MsgBox "Kind user please enter an integral numeric value"
  10.     End If
  11.  
Thank you, I will give this a try and let you know if I have any troubles with it.

Lena
Nov 20 '06 #3
OK..that worked. Although now the users can enter 1.1 as the sort number (want whole numbers only). I did have a line of code that seemed to have kept that from happening, but if I use it, it catches whole numbers and tells me that I can't use them.

Expand|Select|Wrap|Line Numbers
  1.     If Not Fix(NewSort) Then
  2.         MsgBox "Please enter a whole number (no decimals allowed)"
  3.         Exit Sub
  4.     End If
  5.  
How do I prevent anything but a whole number from being used?

Thanks!
Lena
Nov 20 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
Try this .. if I understand you correctly?

Expand|Select|Wrap|Line Numbers
  1. If Int(NewSort) <> NewSort Then
  2. MsgBox "Please enter a whole number (no decimals allowed)"
  3. Exit Sub
  4. End If
  5.  
Nov 20 '06 #5
Try this .. if I understand you correctly?

Expand|Select|Wrap|Line Numbers
  1. If Int(NewSort) <> NewSort Then
  2. MsgBox "Please enter a whole number (no decimals allowed)"
  3. Exit Sub
  4. End If
  5.  
Still allows me to enter numbers like 2.1 and etc. Here is all the code for this that I am using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSortOrder_Click()
  2.  
  3.     Dim db As DAO.Database
  4.     Dim mySQL As String
  5.     Dim OldSort As String
  6.     Dim NewSort As Integer
  7.     Dim mySQLRecordCount As String
  8.     Dim rs As DAO.Recordset
  9.     Dim TheCount As Integer
  10.     Dim MaxNum As Integer
  11.     Dim stReturn As String
  12.  
  13.     Set db = CurrentDb
  14.     OldSort = Me!FunctionalQuestionOrder
  15.  
  16.     mySQLRecordCount = "SELECT * FROM tblQuestions" _
  17.         & " WHERE MarkAsDeleted = False" _
  18.         & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  19.         & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  20.  
  21.     Set rs = db.OpenRecordset(mySQLRecordCount)
  22.  
  23.     With rs
  24.         .MoveLast
  25.         .MoveFirst
  26.     End With
  27.  
  28.     TheCount = rs.RecordCount
  29.  
  30.     rs.Close
  31.     Set rs = Nothing
  32.  
  33.     If TheCount = 1 Then
  34.         MsgBox "There is only one question in this area and no need to change the sort order."
  35.         Exit Sub
  36.     End If
  37.  
  38.     stReturn = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  39.     If Len(stReturn) And IsNumeric(stReturn) Then
  40.         NewSort = CInt(stReturn)
  41.     Else
  42.         Exit Sub
  43.     End If
  44.  
  45.     If Not IsNumeric(NewSort) Then
  46.         MsgBox "Please enter a number"
  47.         Exit Sub
  48.     End If
  49.  
  50.     If NewSort = OldSort Then
  51.         MsgBox "Same Number Entered"
  52.         Exit Sub
  53.     End If
  54.  
  55. '    If Not Fix(NewSort) Then
  56. '        MsgBox "Please enter a whole number - no decimals allowed)"
  57. '        Exit Sub
  58. '    End If
  59.  
  60.     If Not IsNumeric(NewSort) Then
  61.         MsgBox "You didn't enter a number"
  62.         Exit Sub
  63.     End If
  64.  
  65.     If Int(NewSort) <> NewSort Then
  66.         MsgBox "Please enter a whole number (no decimals allowed)"
  67.         Exit Sub
  68.     End If
  69.  
  70.     If NewSort < 1 Then
  71.         MsgBox "Sort Order Can't be less than 1"
  72.         Exit Sub
  73.     End If
  74.  
  75.     MaxNum = CInt(DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  76.  
  77.     If NewSort > MaxNum Then
  78.         MsgBox "Sort Order number can not be bigger than the number of questions being sorted.  " _
  79.           & vbCrLf & vbCrLf & "If you wish to change the sort order, please try again using a valid " _
  80.           & "number."
  81.         Exit Sub
  82.     End If
  83.  
  84.     If CInt(NewSort) > CInt(OldSort) Then
  85.  
  86.         mySQL = "UPDATE tblQuestions" _
  87.             & " SET FunctionalQuestionOrder = 0 " _
  88.             & " WHERE FunctionalQuestionOrder = " & CInt(OldSort) _
  89.             & " AND MarkAsDeleted = False" _
  90.             & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  91.             & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  92.  
  93.         db.Execute mySQL
  94.  
  95.         mySQL = "UPDATE tblQuestions" _
  96.             & " SET FunctionalQuestionOrder = ([FunctionalQuestionOrder] -1)" _
  97.             & " WHERE FunctionalQuestionOrder BETWEEN " & CInt(OldSort) + 1 & " AND " & CInt(NewSort) _
  98.             & " AND MarkAsDeleted = False" _
  99.             & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  100.             & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  101.  
  102.         db.Execute mySQL
  103.  
  104.         mySQL = "UPDATE tblQuestions" _
  105.             & " SET FunctionalQuestionOrder =  " & CInt(NewSort) _
  106.             & " WHERE FunctionalQuestionOrder = 0 " _
  107.             & " AND MarkAsDeleted = False" _
  108.             & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  109.             & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  110.  
  111.         db.Execute mySQL
  112.     ElseIf CInt(NewSort) < CInt(OldSort) Then
  113.  
  114.         mySQL = "UPDATE tblQuestions" _
  115.             & " SET FunctionalQuestionOrder = 0 " _
  116.             & " WHERE FunctionalQuestionOrder = " & CInt(OldSort) _
  117.             & " AND MarkAsDeleted = False" _
  118.             & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  119.             & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  120.  
  121.         db.Execute mySQL
  122.  
  123.         mySQL = "UPDATE tblQuestions" _
  124.             & " SET FunctionalQuestionOrder = ([FunctionalQuestionOrder] +1)" _
  125.             & " WHERE FunctionalQuestionOrder BETWEEN " & CInt(NewSort) & " AND " & CInt(OldSort) - 1 _
  126.             & " AND MarkAsDeleted = False" _
  127.             & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  128.             & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  129.  
  130.         db.Execute mySQL
  131.  
  132.         mySQL = "UPDATE tblQuestions" _
  133.             & " SET FunctionalQuestionOrder =  " & CInt(NewSort) _
  134.             & " WHERE FunctionalQuestionOrder = 0 " _
  135.             & " AND MarkAsDeleted = False" _
  136.             & " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
  137.             & " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
  138.  
  139.         db.Execute mySQL
  140.     End If
  141.  
  142.     MyTrackChanges "Sort Order", Me.FunctionQuestionRecID, CInt(OldSort), CInt(NewSort), _
  143.       "Sort Order Changed from " & CInt(OldSort) & " to " & CInt(NewSort), False
  144.  
  145.     Me.txtSort = Me.FunctionalQuestionOrder
  146.  
  147. '    Me.Repaint
  148.     Dim varRec
  149.  
  150.     varRec = Me.FunctionQuestionRecID
  151.  
  152.     Me.Requery
  153.  
  154.     Set rs = Me.RecordsetClone
  155.     rs.FindFirst "[FunctionQuestionRecID] = " & varRec
  156.     Me.Bookmark = rs.Bookmark
  157.  
  158. End Sub
  159.  
Lena
Nov 20 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Try something like this ...

Expand|Select|Wrap|Line Numbers
  1.  Dim i As Integer 
  2.  
  3. stReturn = InputBox("Please enter a new Sort # between 1 and " & _
  4. DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
  5.  
  6. If Len(stReturn) Then
  7.  
  8.     For i=1 to Len(stReturn)
  9.      'Check that each character is numeric
  10.      If Not IsNumeric(Mid(stReturn, i, 1)) Then
  11.         MsgBox "Please enter a whole number (no decimals allowed)"
  12.         Exit Sub
  13.      Else
  14.         NewSort = CInt(stReturn)
  15.      End If
  16.     Next i
  17.  
  18. Else
  19.     MsgBox "Please enter a whole number (no decimals allowed)"
  20.     Exit Sub
  21. End If
  22.  
Nov 20 '06 #7
Thanks that works GREAT!

Lena
Nov 21 '06 #8
MMcCarthy
14,534 Expert Mod 8TB
Thanks that works GREAT!

Lena
You're welcome.
Nov 21 '06 #9
willakawill
1,646 1GB
You're welcome.
You can also do this a little more simply with:
Expand|Select|Wrap|Line Numbers
  1. If InStr(stReturn, ".") Then
  2.    MsgBox "Fingers off the decimal point button thank you"
  3. End If
  4.  
or words to that effect :)
Nov 21 '06 #10
MMcCarthy
14,534 Expert Mod 8TB
You can also do this a little more simply with:
Expand|Select|Wrap|Line Numbers
  1. If InStr(stReturn, ".") Then
  2. MsgBox "Fingers off the period button thank you"
  3. End If
  4.  
or words to that effect :)
I agree based on the original requirement. Just though I'd turn it into a catch all rather than just checking for a decimal point.

Just me being pedantic as usual. ;)

Mary
Nov 21 '06 #11
You can also do this a little more simply with:
Expand|Select|Wrap|Line Numbers
  1. If InStr(stReturn, ".") Then
  2.    MsgBox "Fingers off the decimal point button thank you"
  3. End If
  4.  
or words to that effect :)
Thanks for showing me a simple way also. It is nice that with Access there are many ways to get the same thing done!

Lena
Nov 21 '06 #12

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
0
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.