I have a form which is opened by with - DoCmd.OpenForm "fEditTitle", acNormal, , , , acDialog, "Key=" & txtKey
The Form Load for fEditTitle is - Private Sub Form_Load()
-
Me.Filter = OpenArgs
-
Me.FilterOn = True
-
End Sub
So far, so good. The form opens with all controls displayed correctly. When I attempt to change a textbox, the following fires - Private Sub txtTitle_Change()
-
Call TidyForm(txtTitle.Text)
-
End Sub
and the code for TidyForm is - Private Sub TidyForm(strTitle As String)
-
Dim curValue As Currency
-
Dim wkTitle As String
-
wkTitle = strTitle
-
curValue = Val(wk)
-
...
-
End Sub
In the immediate window, I then try
and get the same error '13'. Much is locked because the form is modal. So I close the form, and the immediate window works, but the code, now stopped, will not get by the statement "curValue = Val(wk)". "CurValue = CInt(wk)" is OK if wk is numeric, so VBA can find the function libraries.
I've done a Compact and Repair, and a Decompile. I've done Debug->Compile and there are no errors. I changed the offending statement to assign into a Variant instead of Currency, but no good.
What is wrong?
9 13086 @OldBirdman
Hello OldBirdman, where is the Declaration for wk, where is it Initialized, and what does it Represent?
Error in moving relevant code to forum. Code should have read - Private Sub TidyForm(strTitle As String)
-
Dim curValue As Currency
-
Dim wkTitle As String
-
wkTitle = strTitle
-
curValue = Val(wkTitle)
-
...
-
End Sub
I always have "Option Explicit" and run Debug->Compile, so it can't be that easy an error. I'm sorry about the typo, but if that were my error, I would have expected unknown variable and not error 13.
@OldBirdman
The following code will work nicely, and will always ensure that the Value typed into [txtTitle] can always be converted to Currency. You will always get a Type Mismatch on any Non-Numeric Value entered into [txtTitle], except a (.), since you are attempting to Coerce it into a Currency data Type, namely curValue. - Private Sub TidyForm(strTitle As String)
-
On Error GoTo Err_Tidyform
-
Dim curValue As Currency
-
-
'Will produce Type Mismatch Error (13) if the Vale contained in the Text
-
'Property cannot be converted to Currency
-
curValue = CCur(strTitle)
-
-
Exit_Tidyform:
-
Exit Sub
-
-
Err_Tidyform:
-
Select Case Err.Number
-
Case 13 'Type Mismatch - remove entry since it cannot be
-
'converted to Currency
-
Me![txtTitle] = Null
-
Case Else
-
MsgBox Err.Description & Err.Number, vbExclamation, "Error in Tidyform()"
-
End Select
-
Resume Exit_Tidyform
-
End Sub
I don't want to know whether txtTitle is a number, I want the value of the leading digits, if any. This is so I can sort the titles using the value of the leading numbers instead of the text.
According to Access Help, Val() always returns a number (except if argument is null). If no leading digits, a zero is returned, which I test for and change to 9999999999, so the number sort first.
Even ignoring the currency, this fails. Assignment to a Long or Variant, I get error 13.
I have just run your code (in Access 2003) and it works fine if I supply strTitle with text, numeric or mixed.
Try putting a breakpoint at "wkTitle = strTitle" and see what value of strTitle is accutally getting to the Val(wkTitle) statement.
wkTitle has the value "3 Way", the name of a movie. I know this because the code stops with error 13, and I can mouseover or ?wkTitle. Notice from my original post I tried the same function in the immediate window with the same result. ?Val("12 Dozen") gets error 13 in immediate window, but ?CInt("12.22") returns a 12, which is correct.
I suspect that the library reference is incorrect.
Typing this response, I realize that I do have a field in a table called Val. Is this my problem? It is never referenced within VBA as a variable. It does occur within query statements, within quotes, in many places in VBA. strSQL = "... ORDER BY Val, Title" for example.
Forget it. This is the problem. I was using the name Val for a field in a table, and the error 13 / type mismatch was that Val() conflicts with rst.Val, even though Val doesn't appear outside quotes in the VBA code.
Thanks ADezii and Lysander for your time. I wouldn't have found it without your help. In typing my previous response, I started to become aware when I realized maybe a library reference was bad, but then other references were OK.
Checking for a field or function called Val was my next thought.
The most common occurence of this is having a field called "Name" which is another reservered word. It would be nice if Access could enforce the reservered words and stopped us using them as variables or fields.
Glad it is all fixed now.
Yes, and it would also be nice if this possibility were documented for this error. A Google search to try to solve this always assumes a typo or other 'stupid' error, whereas avoiding keywords is a real hassle. There are too many to remember. In this case, I should have remembered, but variables in VBA can't be keywords, but I don't remember reading that table field names can't be VBA keywords. Doesn't matter until you start using VBA, then it bytes you in the ...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ed |
last post by:
Hello,
I took a course in asp about 2 years ago and I was
practicing with IIS 5.0. Then I put it down for a while.
Now trying to get back to it. I can't run asp files from
subdirectories of...
|
by: Jenna Olson |
last post by:
Hi all-
I've never seen this particular issue addressed, but was wondering if
there's anything to support one way or another. Say I have a class:
class ManipulateData
{
public:...
|
by: mg |
last post by:
How can I run an .exe using C# from within the code behind of a WebForm app?
|
by: billr |
last post by:
I have developed a small API for taking care of a lot of boiler plate stuff
in a multi formed windows application, for example setting up a messaging
thread framework.
New Forms, in the...
|
by: Bob Day |
last post by:
Using vs2003, vb.net
I start a thread, giving it a name before start. Code snippet:
'give each thread a unique name (for later identification)
Trunk_Thread.Name = "Trunk_0_Thread"
' allow...
|
by: Brett Wesoloski |
last post by:
I am new to VS2005.
I changed my program.cs file to be a different form I am working on. But
when I go to run the application it still brings up the form that was
originally declared as new. ...
|
by: Lee Crabtree |
last post by:
I remember when I was first getting into .NET Forms programming that
there was a rather emphatic rule about not constructing a form before
calling Application.Run with it. So this:
...
|
by: David Thielen |
last post by:
Hi;
In our setup program how do I determine if I need to run "aspnet_regiis –i"
and if so, is there an API I can calll rather than finding that program on
the user's disk and calling it?
--...
|
by: traceable1 |
last post by:
Is there a way I can set up a SQL script to run when the instance
starts up?
SQL Server 2005 SP2
thanks!
|
by: mxdevit |
last post by:
Task: run application from ASP.NET
for example,
you have a button on ASP.NET page, when press this button - one
application is invoked.
the code to run application (for example, notepad) is...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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,...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |