UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Storing Form Textbox Name Into Variable, Access 2007    
 
   
eacollie
post Apr 16 2018, 08:32 AM
Post#1



Posts: 704
Joined: 15-January 05
From: Tennessee


I'm sure this has been done before but can't find an example, so if someone can direct me I would greatly appreciate!

I have multiple textboxes on a form and want to have one procedure that will handle the click event for each.
I think if I save the control name into a variable, I can use that to do what I need (and that's what I'm having a problem finding).

I have tried the following:
Dim eventid as string
eventid = Me.Ctl39.Name

But get "expression not defined in context" for eventid value

Thank you!
Go to the top of the page
 
missinglinq
post Apr 16 2018, 08:45 AM
Post#2



Posts: 4,551
Joined: 11-November 02



Where, exactly, are you trying this code? Placing it in a Form's module, where a Control named Ctl39 actually exists, doesn't raise this error.

But one has to wonder how one procedure could possibly handle the OnClick event for all Controls. What, exactly, do you want this procedure to so?

Linq ;0)>
Go to the top of the page
 
eacollie
post Apr 16 2018, 08:56 AM
Post#3



Posts: 704
Joined: 15-January 05
From: Tennessee


Thank you.

I'm experimenting with this in one control's on-click event. It doesn't result in an error but nothing is stored in the variable.

I have a form (1) with multiple textboxes. When the user clicks on one of these textboxes, I need to pick up information I can use in a query (which will open another form (2) with this information that can be edited, etc).

Hope that makes sense.
Go to the top of the page
 
zaxbat
post Apr 16 2018, 09:26 AM
Post#4



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


I was also stuck on that....did not want to create the event for each and every room.
Go to the top of the page
 
nuclear_nick
post Apr 16 2018, 09:32 AM
Post#5



Posts: 1,618
Joined: 5-February 06
From: Ohio, USA


I can help... I'm just not quite understanding 'why'...

If you could 'air code' a for-instance... like...
CODE
user clicks text box
text box name captured into variable
variable used to ...


Because there are a few ways to do this. I have three that I've used, depending. Two are easy, one is difficult, all depend on what the end result is going to be.

I also don't understand 'open another form with this information that can be edited...' because... the purpose of a text box on a form is so you can edit/view the information, why do you need to create more hoops?
Go to the top of the page
 
eacollie
post Apr 16 2018, 09:44 AM
Post#6



Posts: 704
Joined: 15-January 05
From: Tennessee


Thank you.

This involves room reservations and the form is to display at-a-glance all rooms reserved/empty for any selected date or date range. I believe I have the form running correctly thanks to the very kind help of zaxbat and theDBguy.

So, for instance...
user clicks on text box for a particular room
this opens the reservation form showing who is in this room and for how long

I'm using a form, as opposed to a report, because I need to have this functionality.

Thank you and hope that makes sense.
Go to the top of the page
 
nuclear_nick
post Apr 16 2018, 09:51 AM
Post#7



Posts: 1,618
Joined: 5-February 06
From: Ohio, USA


So you really don't need this at all...

The easiest way would be to create a continuous form (a subform of all the rooms inside a surrounding main form) with a button that displays more information for the room ("record") selected on the continuous form, correct?

So it's not the control you want passed.. it's the 'RoomID' you want passed to another form that displays more information about the room.

At least that is the way I'd go about it. That way when more rooms are added, or rooms are taken away, you don't have to modify the form by removing text boxes of rooms that don't exist anymore, or add new rooms. They instead have a 'record' or not.

Make sense?
Go to the top of the page
 
eacollie
post Apr 16 2018, 10:03 AM
Post#8



Posts: 704
Joined: 15-January 05
From: Tennessee


Yes, it's the "roomid" that I'm trying to pick up into a variable.

The form's design (by request not by my choice) is a continuous form with a data source of a crosstab query so I don't think I can pick up the "roomid" from this. If I name each control with this information (roomid) I can pick it up that way and send the "roomid" on its way to do the things it needs to do.
Go to the top of the page
 
nuclear_nick
post Apr 16 2018, 10:12 AM
Post#9



Posts: 1,618
Joined: 5-February 06
From: Ohio, USA


Ah.

For clarity, you don't need the 'control name', you need the 'control value', correct?
Go to the top of the page
 
eacollie
post Apr 16 2018, 10:24 AM
Post#10



Posts: 704
Joined: 15-January 05
From: Tennessee


No, because the control "value" is the "count" of the reservations for each room. I've made each textbox control's "name" as the roomid, so was hoping I could somehow pick this up into a variable. The crosstab query's "column" header is also the roomid but don't think I can pick that up. either.
Go to the top of the page
 
nuclear_nick
post Apr 16 2018, 10:45 AM
Post#11



Posts: 1,618
Joined: 5-February 06
From: Ohio, USA


If the room ID is in the control name, then...

In this example, then, we'll say you just want to open a form 'frmRoomInformation'.

Here's one way...
CODE
Private Sub OpenRoomInfo(ctl as Control)
  'validate RoomID from ctl.Name
  'open frmInformation with the open argument of validated RoomID
End Sub

Then each control would need...
CODE
Private Sub Ctl39_Click
  OpenRoomInfo Ctl39
End Sub


Here's a second way...
CODE
Private Sub OpenRoomInfo(ctlName as String)
  'validate RoomID from ctlName
  'open frmInformation with the open argument of ctlName (or validated RoomID)
End Sub

Then each control would need...
CODE
Private Sub Ctl39_Click
  OpenRoomInfo Ctl39.Name
End Sub


That's just a few ways.
This post has been edited by nuclear_nick: Apr 16 2018, 10:46 AM
Go to the top of the page
 
eacollie
post Apr 16 2018, 11:58 AM
Post#12



Posts: 704
Joined: 15-January 05
From: Tennessee


Thanks so much! I think this will work well. I'll give it a try.
Go to the top of the page
 
zaxbat
post Apr 16 2018, 12:01 PM
Post#13



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


Pretty sure I already gave this to you in a zipped demo i did for you a while back.

Each textbox in your form can have the same function call poked into its click event..... (that is what keeps you from having to make a routine for each box)

Then in the function you can get the activecontrol.name (that is what you want....with that name you can do all else you are trying to do)

If you are using continuous form.....I tried it too but it is slow and clunky.....but the datasheet (rather than continuous form) is 2 or 3 times faster and you can cursor up down back forth as you would expect...but cannot do in the continuous form.
This post has been edited by zaxbat: Apr 16 2018, 12:06 PM
Go to the top of the page
 
eacollie
post Apr 16 2018, 12:51 PM
Post#14



Posts: 704
Joined: 15-January 05
From: Tennessee


Thank you zaxbat. How did I miss your post? I'm so sorry. I've downloaded it (RoomUsage1.0) and will take a look. Thank you so much for all your work! It should answer all my questions I'm sure.

Thanks again!
Go to the top of the page
 
zaxbat
post Apr 16 2018, 01:06 PM
Post#15



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


I have made quite a few changes since that version...let me put up a current one.

That version is on continuous form...looks nice enough, but slow and clunky and can't cursor around on screen.

Have it in a datasheet now....so Access does a lot more of the work for me. I see this format as an excellent User interface approach to many many different applications...so I want to get it working really well.

WARNING: because both the form definitions and the VBA code are copied from the templates.....it is easy to update the wrong area....all work concerning the forms from template must be edited in the template or it will just be lost next time you regenerate the form(s) from the template(s).
This post has been edited by zaxbat: Apr 16 2018, 01:24 PM
Attached File(s)
Attached File  ROOMUSAGE1.7.zip ( 143.2K )Number of downloads: 13
 
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    17th October 2018 - 07:33 PM