473,396 Members | 1,996 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.

Convert string to a Form object

Hi,
I found some material about this topic but it all refered to vb6.
I have a table which contains names of the forms in my system. After getting the form name out of the table, i want to set the "AllowEdits" property of that form to false, but for that i need to convert the string which contains the form name into a Form object, at least so i think.. here is a piece of my code:
Expand|Select|Wrap|Line Numbers
  1. Do While Not rs.EOF
  2.     Select Case rs("formNum")
  3.     Case 1:
  4.     rsForms.FindFirst ("formNum = ") & rs("formNum")
  5.     If rsForms.NoMatch = False Then
  6.         strFormName = rsForms("formEnglishName")
  7.         strFormName.AllowEdits = False
  8.         ....
  9.  
strFormName holds the form name, but what should i do in order for the last line (in bold) to work?
Thanks in advance
May 10 '10 #1
10 10137
Megalog
378 Expert 256MB
Are you delcaring strFormName as a form type, not a string?

Like:
Expand|Select|Wrap|Line Numbers
  1. Dim strFormName As Form
May 10 '10 #2
@Megalog
Hi Megalog,
I actually declared it as string. That way i can assign it the form name, but can't assign form property (such as AllowEdits). And if i declare it as Form, than i can assign the property but don't have the name..
May 10 '10 #3
NeoPa
32,556 Expert Mod 16PB
There are collections available that allow you to pass a string parameter to select the matching item.
Expand|Select|Wrap|Line Numbers
  1. {Application.}Forms     All currently open forms.
  2. CurrentProject.AllForms All forms in the project.
Forms("YourFormName") returns that form as long as it's already open and available. The {Application.} part is optional.
May 10 '10 #4
Megalog
378 Expert 256MB
This can go in after line 5 from your initial posting:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm rsForms!formEnglishName, acDesign
  2. If Forms(rsForms!formEnglishName).AllowEdits = True Then
  3.     Forms(rsForms!formEnglishName).AllowEdits = False
  4. End If
  5. DoCmd.Close acForm, rsForms!formEnglishName, acSaveYes
May 10 '10 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Just out of curiosity what are you using this for?
May 10 '10 #6
Wow, it works! Thank you Megalog!:) I just added acHidden to window mode, so it won't pop.
TheSmileyOne, i'm trying to implement restrictions for users. I created a form with a listbox filled with form names, so that whoever sets the configurations will choose set of forms for each worker, which he will not be allowed to modify. It's all my creation, so i'm sure it's not the most clever way, and i'm sure it will be modified not once, but at least what i have now works, thanks again.
Now i'm thinking about a way to add an option to choose exactly what restriciton will be implemented for each form, something like checkboxes for edits/additions/deletions.
May 11 '10 #7
Is there a way to remember listbox selection?
The process is: I choose some values (form names) in the listbox, press button "save choice", then my code activates and the values go in the table as supposed to, but the next time i enter the form the listbox is fresh, and i want it to be exactly as it was when i left it (the chosen lines must be black). I thought maybe on form Load event go through the table which holds the chosen values, and make them appear as chosen, but how?
May 11 '10 #8
TheSmileyCoder
2,322 Expert Mod 2GB
This is some code I wrote myself, to convert the stored values into a comma delimite list, and store it in a hidden textbox, bound to a hidden TEXT field. (of course this only works if the length of the string wont exceed 255)

I only use this in a search form, to remember the users last performed search, so its not critical. If its something you need to store what user can access, I might want to write the data to tables instead of a string.

Anyways, here it is, and im sure you can modify it to read/restore the data of the table.
To STORE the values
Expand|Select|Wrap|Line Numbers
  1. Private Sub list_Status_BeforeUpdate(Cancel As Integer)
  2.  
  3.     StoreList Me.list_Status, Me.tb_status
  4.  
  5. End Sub
To RESTORE the values
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. 'Restore the list selections
  3.     restoreList Me.list_Status, Me.tb_status
  4.     restoreList Me.list_Grade, Me.tb_Severity
  5.  
  6. End Sub

The procedures used:
Expand|Select|Wrap|Line Numbers
  1. Public Sub StoreList(ctrlListBox As Control, ctrlTextBox As Control)
  2. 'Lets store the items selected in the listbox
  3.     'Check that ctrlListBox is truly a listbox
  4.     If ctrlListBox.ControlType <> acListBox Then
  5.         MsgBox "This is not a listbox!"
  6.         Exit Sub
  7.     End If
  8.  
  9.     'Check that ctrlTextbox is truly a textbox
  10.     If ctrlTextBox.ControlType <> acTextBox Then
  11.         MsgBox "This is not a textbox!"
  12.         Exit Sub
  13.     End If
  14.  
  15.     'Dim variables
  16.         Dim lvItem As Variant
  17.         Dim intI As Integer
  18.         Dim strStorage As String
  19.  
  20.     'Loop through selected items
  21.         For Each lvItem In ctrlListBox.ItemsSelected
  22.             strStorage = strStorage & "," & ctrlListBox.ItemData(lvItem)
  23.         Next
  24.  
  25.     'If no items are selected then
  26.         If strStorage & "" <> "" Then
  27.             ctrlTextBox = Right(strStorage, Len(strStorage) - 1)
  28.             Else
  29.             ctrlTextBox = Null
  30.         End If
  31.  
  32.  
  33.     Set lvItem = Nothing
  34.  
  35. End Sub
Expand|Select|Wrap|Line Numbers
  1. Public Sub restoreList(ctrlListBox As Control, ctrlTextBox As Control)
  2.     'Load the listbox
  3.     On Error GoTo exitSub
  4.  
  5.     'Init variables
  6.         Dim intI As Integer
  7.         Dim intCount As Integer
  8.         Dim myVar As Variant
  9.     'Unmark all
  10.         DoCmd.Echo (False) 'Turn of painting
  11.         For intI = 0 To ctrlListBox.ListCount
  12.             ctrlListBox.Selected(intI) = False
  13.         Next
  14.  
  15.     'If nothing is selected, go ahead and end sub
  16.         If ctrlTextBox & "" = "" Then GoTo endSub
  17.  
  18.     'How many items are marked as selected
  19.         intCount = CharCount(ctrlTextBox, ",")
  20.  
  21.     Dim intJ As Integer
  22.     'Restore teh selections
  23.         For intI = 0 To intCount
  24.             myVar = CVar(Split(ctrlTextBox, ",")(intI))
  25.             For intJ = 0 To ctrlListBox.ListCount
  26.                 If ctrlListBox.ItemData(intJ) = myVar Then
  27.                     ctrlListBox.Selected(intJ) = True
  28.                 End If
  29.  
  30.             Next
  31.         Next
  32.  
  33. endSub:
  34.     DoCmd.Echo (True)
  35.  
  36. Exit Sub
  37. exitSub:
  38. Debug.Print Err.Number & " - " & Err.Description
  39. DoCmd.Echo (True)
  40.  
  41. End Sub
May 11 '10 #9
Megalog
378 Expert 256MB
If you're using A2007, you can create a multivalue field in the table, and bind the listbox to it. Then it'll remember all the selections you make. Quite quick to set up, but the downside is that using MV fields is a real pain if you need to extract values out of there for use elsewhere.
May 11 '10 #10
TheSmileyOne, thanks a lot for the code. My values are stored it a table anyway, but i did use the ".Selected" property, it does paint the line as chosen, for some reason i didn't find it earlier ... now i have another problem, but i'll try to figure it out.
Megalog, i'm using Access 2003
May 12 '10 #11

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

Similar topics

5
by: JimMenees | last post by:
I know there's an easy answer to this which is escaping me: -------------------------------------------------------------------------- ----------------------- I have clickable thumb images which...
11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
2
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored...
1
by: xendrax | last post by:
I was told on this site eval was bad but its the only way i can work out how to do it.. their example was use var imdesc = document.myform.value not var imdesc = eval("document.myform." +...
5
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
3
by: Ursula | last post by:
Is it possible to convert a string in a file. The problem is this: I have an object string that is a file xml and I want to pass to Deserialize function, but Deserialize function expect an object...
3
by: amit75 | last post by:
hi every body. Presently I am using vb.net. Now i am facing a problem that how to convert a string value to vb.net form object
2
by: Blackmore | last post by:
I am trying to use javascript to calculate the difference between two form inputted dates and return the result to another form object. When I load up the page with the function on my web browser...
7
devonknows
by: devonknows | last post by:
Hi, The problem im having is, Im creating a user control. The user (via the Property Page's) will set his own menu titles, and the choose a form of which that title links to. If that makes sense. ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.