If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > match string name to form name in vba

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jul 2005
Posts: 30
match string name to form name in vba

I have a form that updates with a list box. A button on the form opens a chart. The code I have works great and both forms update when the selection changes in the list box.
What I would like to do is have it work for any form I specify in a variable
without having to hard code the form name in the requery statment.
All tries at variable substitution fail. Of course a string doesn't work when a
form is required. Is there some way around this? Is there a way to get the form name to change with the string name.

Public Function move_up(ByVal frmvar As Form)

Dim varnames As String
varnames = "frmchtfld"

Dim rs As Object
If CurrentProject.AllForms(varnames).IsLoaded Then
Set rs = frmvar.Recordset.Clone
rs.FindFirst "[well name] = '" & frmvar![wells] & "'"
If Not rs.EOF Then frmvar.Bookmark = rs.Bookmark
Forms!frmchtfld.Requery

Else
Set rs = frmvar.Recordset.Clone
rs.FindFirst "[Well name] = '" & frmvar![wells] & "'"
If Not rs.EOF Then frmvar.Bookmark = rs.Bookmark


End If
End Function

Any help would be appreciated.
Reply With Quote
  #2 (permalink)  
Old
Moderator
 
Join Date: Mar 2009
Posts: 5,172
You could try something like this:
Code:
    Dim strFName As String
    
    strFName = "F_Billing_Customers_List"
    Eval "Forms!" & strFName & ".Requery"
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Oct 2004
Location: Oxfordshire, UK
Posts: 89
You can use a string variable in place of hard coded names. You've just got to lose the bang operator. Let's say you want to reference a control called "x" on a form named "y" then you can do this:

Forms("x").Controls("y").Value = "z" In fact default class properties mean that you can shorten this to:
Forms("x")("y") = "z"

All of the quoted characters could be replaced with variables.

In the same way you might pass a variable a form sub procedure like this
x = "MyForm"
y = 1
Call Forms(x).MySub(y)
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jul 2005
Posts: 30
Sinndho:

Code works great with eval function.
Eval "Forms!" & strVariable & ".Requery"

Thanks
Darejamr
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On