473,396 Members | 2,020 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.

How to pass a string field as a parameter

sueb
379 256MB
I'm trying to tighten up the code in my database, so there is a function that I've made public. However, I don't have the syntax right for passing in the field that contains the parameter data.

Here's the public function:

Expand|Select|Wrap|Line Numbers
  1. Function Open_eChart(strChartNum As String)
  2. On Error GoTo Err_Open_eChart
  3.  
  4.     Dim retVal As Variant
  5.     Dim strPartialPath As String
  6.     Const conPAth As String = "V:\IUR\eCharts\"
  7.  
  8.     If IsNull(strChartNum) Then Exit Function
  9.  
  10.     strPartialPath = Replace(Replace(strChartNum, "\", ""), ",", "_")
  11.  
  12.     If Dir$(conPAth & strPartialPath, vbDirectory) = "" Then MkDir (conPAth & strPartialPath)
  13.  
  14.     retVal = Shell("Explorer.exe " & conPAth & strPartialPath, vbNormalFocus)
  15.  
  16. Exit_Open_eChart:
  17.    Exit Function
  18.  
  19. Err_Open_eChart:
  20.     MsgBox Err.Description
  21.     Resume Exit_Open_eChart
  22.  
  23. End Function
  24.  
and here's how I'm calling it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_eChart_Click()
  2.     'Open_eChart Me![ChartNum]
  3.     Open_eChart (Me![ChartNum])
  4. End Sub
  5.  
Both the lines in the call give the same error, which is a compile error saying that this is an "invalid use of property", and pointing to the "ChartNum" field.

(Also, do you think I need the error handling in the public function? It seems pretty sturdy on its own, but I don't know.)
Jan 22 '11 #1

✓ answered by beacon

To answer your last question first, I would remove the error handling until you get the function to work. Then you can test it with the error handling to ensure that everything works the way you were intending. To answer your second to last question next, personally, I would use the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_eChart_Click()  
  2.     Open_eChart (Me.ChartNum) 
  3. End Sub 
  4.  
Try this first and if it works, then you can pretty much disregard the rest of the thread.

Now for the questions (assuming it still doesn't work)...

Have you done any debugging to see what kind of value is getting passed into the function?

I would slap a messagebox before your line #8 in your first block of code and one after it, then re-run the code.

I know this sounds elementary, and for that I apologize in advance, but have you double-checked to ensure that [ChartNum] is a Text field? I've created many a database for patients with ID numbers that sometimes I needed to be numbers and other times I needed to be strings, so to see you call your field [ChartNum] instead of [strChartNum] or [txtChartNum] made me want to make sure you double checked it.

Another thing you can try is to create a local string variable in the function and assign the argument to the variable, then test that out. For instance:

Expand|Select|Wrap|Line Numbers
  1. Function Open_eChart(strChartNum As String) 
  2. On Error GoTo Err_Open_eChart 
  3.  
  4.     Dim strTemp as String
  5.     Dim retVal As Variant 
  6.     Dim strPartialPath As String 
  7.     Const conPAth As String = "V:\IUR\eCharts\" 
  8.  
  9.     strTemp = strChartNum
  10.  
  11.     If IsNull(strTemp) Then Exit Function 
  12.  

6 4981
beacon
579 512MB
To answer your last question first, I would remove the error handling until you get the function to work. Then you can test it with the error handling to ensure that everything works the way you were intending. To answer your second to last question next, personally, I would use the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_eChart_Click()  
  2.     Open_eChart (Me.ChartNum) 
  3. End Sub 
  4.  
Try this first and if it works, then you can pretty much disregard the rest of the thread.

Now for the questions (assuming it still doesn't work)...

Have you done any debugging to see what kind of value is getting passed into the function?

I would slap a messagebox before your line #8 in your first block of code and one after it, then re-run the code.

I know this sounds elementary, and for that I apologize in advance, but have you double-checked to ensure that [ChartNum] is a Text field? I've created many a database for patients with ID numbers that sometimes I needed to be numbers and other times I needed to be strings, so to see you call your field [ChartNum] instead of [strChartNum] or [txtChartNum] made me want to make sure you double checked it.

Another thing you can try is to create a local string variable in the function and assign the argument to the variable, then test that out. For instance:

Expand|Select|Wrap|Line Numbers
  1. Function Open_eChart(strChartNum As String) 
  2. On Error GoTo Err_Open_eChart 
  3.  
  4.     Dim strTemp as String
  5.     Dim retVal As Variant 
  6.     Dim strPartialPath As String 
  7.     Const conPAth As String = "V:\IUR\eCharts\" 
  8.  
  9.     strTemp = strChartNum
  10.  
  11.     If IsNull(strTemp) Then Exit Function 
  12.  
Jan 22 '11 #2
ADezii
8,834 Expert 8TB
  1. Both the Name of your Command Button and Public Function share the exact same Name, namely Open_eChart. This is a No-No. Change the Name of the Function to Open_eChart_2.
  2. Since the Function is not returning a Value, I prefer the following Syntax to Execute the Function:
    Expand|Select|Wrap|Line Numbers
    1. Call Open_eChart_2(Me![ChartNum]) 
Jan 22 '11 #3
beacon
579 512MB
Good eye ADezii
Jan 22 '11 #4
ADezii
8,834 Expert 8TB
Thanks beacon, at least something still works!(LOL).
Jan 22 '11 #5
sueb
379 256MB
Okay, the string-passing works great, guys! But it seems that line #12 (in my original post), intended to make a directory if one doesn't already exist, doesn't work; instead, I get a pop-up error "Path not found". What am I doing wrong there? I actually thought this had been working, but apparently not.

Edit: Never mind, it is working. Not sure why it seemed not to be, but it's all good now--thanks, again!
Jan 24 '11 #6
beacon
579 512MB
If starts not working again, add some breakpoints at that line in your code so you can see what the values are that comprise your path. That way, if something is wrong (maybe has a character you didn't intend on it having) you'll be able to see it and can add additional code rectify the situation from occurring again.
Jan 25 '11 #7

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

Similar topics

5
by: Belinda | last post by:
Hello All I have the following test.asp page which needs one parameter querystr but my querystr is a very long string value. When I send a long value the query string is getting truncated after...
2
by: 00steve | last post by:
Hi, I have a group of records that I need to sort by time field. The time field is a text string (should've been a date/time - I know -doh!) I was wondering if anyone knew how to write a query...
7
by: happy | last post by:
I will reissue my question . How to form and write string field to a disk file in one statement usinf fprintf? my struct as below : struct record { char customer_name; int customer_no;...
3
by: Gopal Prabhakaran | last post by:
Hi Guys Pls help me asap - Can we pass delegate as parameter ? Thanx Gopal Prabhakaran
6
by: NewToCode | last post by:
I built an application aroung the FileSystemWatcher and i am having trouble passing a string from my mainForm to a second form toastForm. Can someone please give me some insight on how to do this....
2
by: MrDotNet | last post by:
Hi I want pass NameValueCollection as parameter in webmethod. I try it but that give me error. Here is Error. You must implement the Add(System.String) method on...
17
by: Jellicle | last post by:
There are some sturct arrays (or struct vectors), such as: struct S1_t { double keyField ; ..// other fields } S1_t s1;
1
by: askcq | last post by:
Can anyone help on this ?? how to pass String as Argument while creating TASK in VXWORKS
6
by: =?Utf-8?B?emlubw==?= | last post by:
I'm trying to pass a delegate as parameter but the code below does not compile. It display an error: 'AddressOf operand must the name of a method(without parantheses)' How can I make it work. ...
7
by: PhilTheGap | last post by:
Hi, I've tried this: <asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave" OnClientClick="SaveParam (<% Util.MaxTags %>)" /> but if fails... Util is a C# class, MaxTags a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
Oralloy
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,...
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
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
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.