473,396 Members | 1,915 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,396 software developers and data experts.

Syntax issue - when strlinkcriteria is a number

I have this code which works fine and will open the form to the correct record but it produces a "Type mismatch" msgbox on opening the record...

the stLinkCriteria consists of two values one of which is a number [AAID] - is the syntax causing this?

************************************************** ******************************************
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command13_Click()
  2. On Error GoTo Err_Command13_Click
  3.  
  4.     Dim stDocName As String
  5.     stDocName = "frmAAResults"
  6.     stLinkCriteria = "[AAID] =" & Me![lstEMPs].Column(0) & " AND [Department]='" & Me![lstEMPs].Column(1) & "'"
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  8.  
  9.  
  10. DoCmd.Close "frmSEARCH-Results"
  11. Exit_Command13_Click:
  12.     Exit Sub
  13.  
  14. Err_Command13_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_Command13_Click
  17.  
  18. End Sub
  19.  
************************************************** ******************************************
May 17 '07 #1
15 2260
puppydogbuddy
1,923 Expert 1GB
Yes, I believe that since AAID is numeric, you have to wrap it with the string (str) function as shown:

stLinkCriteria = Str("[AAID] =" & Me![lstEMPs].Column(0)) & " AND [Department]='" & Me![lstEMPs].Column(1) & "'"
May 17 '07 #2
evn678
8
Yes, I believe that since AAID is numeric, you have to wrap it with the string (str) function as shown:

stLinkCriteria = Str("[AAID] =" & Me![lstEMPs].Column(0)) & " AND [Department]='" & Me![lstEMPs].Column(1) & "'"
Yes, but wouldn't the syntax be:

stLinkCriteria = "[AAID] =" & str(Me![lstEMPs].Column(0)) & " AND [Department]='" & Me![lstEMPs].Column(1) & "'"

?
May 17 '07 #3
Puppydogbuddy – your code produces the error msgbox “Type mismatch” as soon as you click the button and doesn’t open the form

evn678 – your code does the same thing as my original code – it opens the form to the correct record but still produces the error msgbox…

???
May 17 '07 #4
puppydogbuddy
1,923 Expert 1GB
[font=Verdana][size=2]You can try it that way, but I think I probably should have wrapped the entire expression with the CStr function instead of the Str function as shown:[/size][/font]

stLinkCriteria = CStr("[AAID] =" & Me![lstEMPs].Column(0) & " AND [Department]='" & Me![lstEMPs].Column(1) & "'" )
May 17 '07 #5
evn678
8
Puppydogbuddy – your code produces the error msgbox “Type mismatch” as soon as you click the button and doesn’t open the form

evn678 – your code does the same thing as my original code – it opens the form to the correct record but still produces the error msgbox…

???
Go into your table definition and tell us the data types of .Column(0) and .Column(1)
May 17 '07 #6
missinglinq
3,532 Expert 2GB
I assume that AAID is an identification "number." If this is true, there's no valid reason for it data type to be numeric! You should only use a numeric data type for fields that are going to be used in some sort of mathematical calculations, not for fields that just happen to be made up of all "numbers." Tyr changing the data type and run your original code and see what happens.
May 17 '07 #7
puppydogbuddy
1,923 Expert 1GB
Are you referring to the last code I submitted, using the CStr function? That should work.
May 17 '07 #8
I think the number is the issue why I can't figure out BUT

AAID is a number because in the table it looks up to it is an auto number
Department is text

AAID + Dept is the composite key of the table we are searching for

The new code still produces the error msgbox...
May 17 '07 #9
puppydogbuddy
1,923 Expert 1GB
[color=black]
I think the number is the issue why I can't figure out ...
[/color]

[color=black] [/color]

[color=black]None of the syntaxes used previously were correct for combining text and numeric data types in one expression. Hopefully, we can get you the correct expression syntax.[/color]

[color=black] [/color]

[color=black]Let's try the following expression syntax: I simplified it by removing the Column(0) from the numeric component because column(0) is the bound (default) column in that expression and should not be needed. I also added variables for each component of the expression to be able to determine that is evaluated properly.[/color]

[color=black] [/color]

[color=black]Dim iNumericPart As Integer[/color]

[color=black]Dim strTextPart As String[/color]

[color=black] [/color]

[color=black]iNumericPart = [/color]"[AAID] = ” & Me![lstEMPs]

strTextPart = [color=black] “[/color][Department]= '" & Me![lstEMPs].Column(1) & "'"

[color=black] [/color]

stLinkCriteria = iNumericPart & “ AND “ & strTextPart



If the above doesn’t work, you need to go to the debug window and type in the variable name for each component of the expression by itself and let me know which component does not evaluate properly.
May 17 '07 #10
Thank You - I see you dim(ed) an integer AND a string which is what I thought the issue to be all along – so that makes sense – however, go figure - when I trashed the form and made a new one from scratch it works this way:
************************************************** **********************
Private Sub cmdOpenResults_Click()
On Error GoTo Err_cmdOpenResults_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmAAResults"

stLinkCriteria = CStr("[AAID] =" & Me![lstWS].Column(0) & " AND [Department]='" & Me![lstWS].Column(2) & "'")
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, "frmSearchResults"


Exit_cmdOpenResults_Click:
Exit Sub

Err_cmdOpenResults_Click:
MsgBox Err.Description
Resume Exit_cmdOpenResults_Click

End Sub

I am learning sometimes access has gremlins…

But I wanted to know how to dim 2 separate data type variables and you showed me so thanks very much…
May 18 '07 #11
puppydogbuddy
1,923 Expert 1GB
Glad I could help. I am curious about one thing, though.
Your final expression:
stLinkCriteria = CStr("[AAID] =" & Me![lstWS].Column(0) & " AND [Department]='" & Me![lstWS].Column(2) & "'")

is the same as the one I recommended in one of my prior posts (post #5):
stLinkCriteria = CStr("[AAID] =" & Me![lstEMPs].Column(0) & " AND [Department]='" & Me![lstEMPs].Column(1) & "'" )

except that you are referencing a different listbox. Could this have been the problem all along?
May 18 '07 #12
I would have to say no, I changed the order several times, but if it had been the wrong column number it would not have been able to locate the correct record (which it always did)…

The column count determines which field to match against the form’s record, so I am thinking if I had the wrong one it would have crashed...correct?
May 18 '07 #13
puppydogbuddy
1,923 Expert 1GB
The column count determines which field to match against the form’s record, so I am thinking if I had the wrong one it would have crashed...correct?
Not neccessarily, but there would be a noticeable difference in the return values, i.e. the values returned wouldn't make sense in the context of what would be expected.

However, I am referring to the object name, not the order:
CStr("[AAID] =" & Me![lstWS]
.......................vs......................... ...............
CStr("[AAID] =" & Me![lstEMPs]
May 18 '07 #14
Sorry I missed that - yes you are right I did change the listbox name to the current example...so now I am curious, are you saying that the wrong name of the listbox might still have opened the form yet had a mismatch error? I don't think so, I believe it would have debugged and opened to the list box name in the VBE, right?
May 21 '07 #15
puppydogbuddy
1,923 Expert 1GB
Sorry I missed that - yes you are right I did change the listbox name to the current example...so now I am curious, are you saying that the wrong name of the listbox might still have opened the form yet had a mismatch error? I don't think so, I believe it would have debugged and opened to the list box name in the VBE, right?
Yes, it would have to be debugged. I was not referring to the listbox name in that discussion about crashing the system. In that context, I was talking about colums within the listbox.
May 21 '07 #16

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
22
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if...
1
by: Dalan | last post by:
I can't seem to find a workaround of Query Syntax Error. Actually, the query performs just fine, except when the last record on a related subform is deleted, then it generates a Runtime Error 3075...
8
by: p | last post by:
I'm trying to put a query into VBA code and its giving me difficulties. I would like to put the following query: SELECT tbl_Workload.Priority, tbl_Workload.Number AS Num, tbl_Workload.Name,...
3
by: Birky | last post by:
Hello, I’m hoping you can help me out with two issues I’m having with my code. I have an Access Report named Report_Project_Event_Log which I have calling a Form named “Custom_Code_lookup” which...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
33
by: bearophileHUGS | last post by:
I have just re-read the list of changes in Python 2.6, it's huge, there are tons of changes and improvements, I'm really impressed: http://docs.python.org/dev/whatsnew/2.6.html I'll need many...
5
by: Boris Borcic | last post by:
Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
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...
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,...

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.