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.
Re: Access VBA: String to Object Question.
Access VBA question moved to Office Development
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
Re: Access VBA: String to Object Question.
Why do you want to pass it as a String? :confused:
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)
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)
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?