|
-
Mar 27th, 2008, 10:55 AM
#1
Thread Starter
Lively Member
Access VBA: String to Object Question.
Hello, I have a question concerning pasing an argument in the form of a string then converting that string into an object part.
THis question is concerning Acess 2003 and VBA.
Setup:
Form 1 named: frmMyform
in the VBA code on this form i call a function in a Module.
dim formName as string
formName = Me.Name (thus setting formName to "frmMyform")
Function call: myfunction (formName)
------------------------------------
In module i now have the function that recieves the name...
I wish to use the name in the following manner...
dim frm as form
set frm = Forms!formName <------------- Notice how i use the passed variable "formName"... Access tosses an error about it being a string and not part of the object command.
I need to convert the string into the apropriate object type to turn it into a form.
any help would be apreciated.
VB.Net uber-noob since04, Yeababy! 
-
Mar 27th, 2008, 11:03 AM
#2
Re: Access VBA: String to Object Question.
Access VBA question moved to Office Development
-
Mar 27th, 2008, 11:10 AM
#3
Addicted Member
Re: Access VBA: String to Object Question.
I don't know of a better way to do this than to use a select case statement
Code:
select case formName
case "form1name"
set frm = forms!form1
case "form2name"
set frm = forms!form2
end select
If you're going to be crazy, you have to get paid for it or else you're going to be locked up. -- Hunter Thompson
-
Mar 27th, 2008, 12:34 PM
#4
Re: Access VBA: String to Object Question.
Why do you want to pass it as a String? 
It is much easier to just pass the object instead, eg:
Code:
Public Function myfunction (TheForm as form) as DataType
'code here to work with TheForm, eg:
TheForm.Caption = "hello"
End Function
Usage:
Code:
myVariable = myfunction(Me)
-
Oct 3rd, 2008, 09:18 AM
#5
New Member
Re: Access VBA: String to Object Question.
convert string to object
stringO = "Forms!dlgKaart!cmdCancel"
in stringO the controlname is "cmdCancel"
convert "cmdCancel"-string to a control cmdCancel on form "dlgKaart":
dim ctrl as control
dim IntermediateControl as string
set frm = forms("dlgKaart")
.
.
IntermediateControl = eval(stringO & ".name")
set ctrl = frm(IntermediateControl)
-
Jun 19th, 2012, 10:46 AM
#6
New Member
Re: Access VBA: String to Object Question.
I feel like you are addressing the problem I am having, but your code wont just run for me
says 'forms' not defined as function etc.
what I want to do is take in a string from a com object's return, but VBA is claiming 'Object required'
Here's what I'm doing:
Dim sharepointService As SharepointConnector.SharepointConnector
Set sharepointService = New SharepointConnector.SharepointConnector
Dim xmlString As String
xmlString = sharepointService.getListCollection().toString()
note that SharepointConnector type is the Com library in question.
This is vb .net code that created that com library / dll file I'm using.
when I try to return this string into xmlString I get an error:
'object required' on that line xmlString = sharepointService.getListCollection ...
Help?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|