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: -
-
Dim NewSort As Integer
-
-
NewSort = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
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
11 2169
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: -
-
Dim NewSort As Integer
-
-
NewSort = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
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 -
-
Dim NewSort As Integer
-
Dim stReturn As String
-
-
stReturn = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
If Len(stReturn) AND IsNumeric(stReturn) Then
-
NewSort = CInt(stReturn)
-
Else
-
MsgBox "Kind user please enter an integral numeric value"
-
End If
-
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 -
-
Dim NewSort As Integer
-
Dim stReturn As String
-
-
stReturn = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
If Len(stReturn) AND IsNumeric(stReturn) Then
-
NewSort = CInt(stReturn)
-
Else
-
MsgBox "Kind user please enter an integral numeric value"
-
End If
-
Thank you, I will give this a try and let you know if I have any troubles with it.
Lena
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. -
If Not Fix(NewSort) Then
-
MsgBox "Please enter a whole number (no decimals allowed)"
-
Exit Sub
-
End If
-
How do I prevent anything but a whole number from being used?
Thanks!
Lena
Try this .. if I understand you correctly? -
If Int(NewSort) <> NewSort Then
-
MsgBox "Please enter a whole number (no decimals allowed)"
-
Exit Sub
-
End If
-
Try this .. if I understand you correctly? -
If Int(NewSort) <> NewSort Then
-
MsgBox "Please enter a whole number (no decimals allowed)"
-
Exit Sub
-
End If
-
Still allows me to enter numbers like 2.1 and etc. Here is all the code for this that I am using: -
Private Sub cmdSortOrder_Click()
-
-
Dim db As DAO.Database
-
Dim mySQL As String
-
Dim OldSort As String
-
Dim NewSort As Integer
-
Dim mySQLRecordCount As String
-
Dim rs As DAO.Recordset
-
Dim TheCount As Integer
-
Dim MaxNum As Integer
-
Dim stReturn As String
-
-
Set db = CurrentDb
-
OldSort = Me!FunctionalQuestionOrder
-
-
mySQLRecordCount = "SELECT * FROM tblQuestions" _
-
& " WHERE MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
Set rs = db.OpenRecordset(mySQLRecordCount)
-
-
With rs
-
.MoveLast
-
.MoveFirst
-
End With
-
-
TheCount = rs.RecordCount
-
-
rs.Close
-
Set rs = Nothing
-
-
If TheCount = 1 Then
-
MsgBox "There is only one question in this area and no need to change the sort order."
-
Exit Sub
-
End If
-
-
stReturn = InputBox("Please enter a new Sort # between 1 and " & DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
If Len(stReturn) And IsNumeric(stReturn) Then
-
NewSort = CInt(stReturn)
-
Else
-
Exit Sub
-
End If
-
-
If Not IsNumeric(NewSort) Then
-
MsgBox "Please enter a number"
-
Exit Sub
-
End If
-
-
If NewSort = OldSort Then
-
MsgBox "Same Number Entered"
-
Exit Sub
-
End If
-
-
' If Not Fix(NewSort) Then
-
' MsgBox "Please enter a whole number - no decimals allowed)"
-
' Exit Sub
-
' End If
-
-
If Not IsNumeric(NewSort) Then
-
MsgBox "You didn't enter a number"
-
Exit Sub
-
End If
-
-
If Int(NewSort) <> NewSort Then
-
MsgBox "Please enter a whole number (no decimals allowed)"
-
Exit Sub
-
End If
-
-
If NewSort < 1 Then
-
MsgBox "Sort Order Can't be less than 1"
-
Exit Sub
-
End If
-
-
MaxNum = CInt(DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
-
If NewSort > MaxNum Then
-
MsgBox "Sort Order number can not be bigger than the number of questions being sorted. " _
-
& vbCrLf & vbCrLf & "If you wish to change the sort order, please try again using a valid " _
-
& "number."
-
Exit Sub
-
End If
-
-
If CInt(NewSort) > CInt(OldSort) Then
-
-
mySQL = "UPDATE tblQuestions" _
-
& " SET FunctionalQuestionOrder = 0 " _
-
& " WHERE FunctionalQuestionOrder = " & CInt(OldSort) _
-
& " AND MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
db.Execute mySQL
-
-
mySQL = "UPDATE tblQuestions" _
-
& " SET FunctionalQuestionOrder = ([FunctionalQuestionOrder] -1)" _
-
& " WHERE FunctionalQuestionOrder BETWEEN " & CInt(OldSort) + 1 & " AND " & CInt(NewSort) _
-
& " AND MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
db.Execute mySQL
-
-
mySQL = "UPDATE tblQuestions" _
-
& " SET FunctionalQuestionOrder = " & CInt(NewSort) _
-
& " WHERE FunctionalQuestionOrder = 0 " _
-
& " AND MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
db.Execute mySQL
-
ElseIf CInt(NewSort) < CInt(OldSort) Then
-
-
mySQL = "UPDATE tblQuestions" _
-
& " SET FunctionalQuestionOrder = 0 " _
-
& " WHERE FunctionalQuestionOrder = " & CInt(OldSort) _
-
& " AND MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
db.Execute mySQL
-
-
mySQL = "UPDATE tblQuestions" _
-
& " SET FunctionalQuestionOrder = ([FunctionalQuestionOrder] +1)" _
-
& " WHERE FunctionalQuestionOrder BETWEEN " & CInt(NewSort) & " AND " & CInt(OldSort) - 1 _
-
& " AND MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
db.Execute mySQL
-
-
mySQL = "UPDATE tblQuestions" _
-
& " SET FunctionalQuestionOrder = " & CInt(NewSort) _
-
& " WHERE FunctionalQuestionOrder = 0 " _
-
& " AND MarkAsDeleted = False" _
-
& " AND FunctionalAreaID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaID]) _
-
& " AND FunctionalAreaCategoryID " & IIf(IsNull([Forms]![frmEditQuestions]![FunctionalAreaCategoryID]), "Is Null", "=" & [Forms]![frmEditQuestions]![FunctionalAreaCategoryID])
-
-
db.Execute mySQL
-
End If
-
-
MyTrackChanges "Sort Order", Me.FunctionQuestionRecID, CInt(OldSort), CInt(NewSort), _
-
"Sort Order Changed from " & CInt(OldSort) & " to " & CInt(NewSort), False
-
-
Me.txtSort = Me.FunctionalQuestionOrder
-
-
' Me.Repaint
-
Dim varRec
-
-
varRec = Me.FunctionQuestionRecID
-
-
Me.Requery
-
-
Set rs = Me.RecordsetClone
-
rs.FindFirst "[FunctionQuestionRecID] = " & varRec
-
Me.Bookmark = rs.Bookmark
-
-
End Sub
-
Lena
Try something like this ... - Dim i As Integer
-
-
stReturn = InputBox("Please enter a new Sort # between 1 and " & _
-
DLookup("[MaxOfFunctionalQuestionOrder]", "qryMaxSortNumber"))
-
-
If Len(stReturn) Then
-
-
For i=1 to Len(stReturn)
-
'Check that each character is numeric
-
If Not IsNumeric(Mid(stReturn, i, 1)) Then
-
MsgBox "Please enter a whole number (no decimals allowed)"
-
Exit Sub
-
Else
-
NewSort = CInt(stReturn)
-
End If
-
Next i
-
-
Else
-
MsgBox "Please enter a whole number (no decimals allowed)"
-
Exit Sub
-
End If
-
Thanks that works GREAT!
Lena
Thanks that works GREAT!
Lena
You're welcome.
You're welcome.
You can also do this a little more simply with: -
If InStr(stReturn, ".") Then
-
MsgBox "Fingers off the decimal point button thank you"
-
End If
-
or words to that effect :)
You can also do this a little more simply with: -
If InStr(stReturn, ".") Then
-
MsgBox "Fingers off the period button thank you"
-
End If
-
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
You can also do this a little more simply with: -
If InStr(stReturn, ".") Then
-
MsgBox "Fingers off the decimal point button thank you"
-
End If
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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....
|
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...
|
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...
|
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,...
|
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:
...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |