I must be really bad at asking questions, none of them get answers

B

BBanks

Hopefully I can ask this question so that someone understands my problem and
is properly motivated to help me.
I have a form that will include up to twelve records.
I am wanting to create buttons at the bottom of the form that only show up
when a new record is created.
When this button is clicked, it should go its corresponding record.
I also want the name of the button to reflect the DeviceID that is
co-located in the same form.
And finally, I want a button for every record that has data to show when the
form is opened.
I am fairly new to VB and know a very limited amount. If this makes me a
useless piece of trash, I am sorry.

Please Help!!!
 
B

Barry Gilbert

In your form's footer, create 12 buttons and name them cmd0 through cmd11.
Set the visible property of all these buttons to False. This will hide them.
In the OnClick event of every one of these buttons, put this code:

Me.Recordset.AbsolutePosition = Me.cmd0.Tag 'substitue the name of each
control for the cmd0 part here.

In the form's OnLoad event, put this code:
Dim i As Integer
With Me.RecordsetClone
Do Until .EOF
Me.Controls("cmd" & i).Visible = True
'Is DeviceId a field in your table? I wasn't sure from your
description.
Me.Controls("cmd" & i).Caption = .Fields("DeviceId")
Me.Controls("cmd" & i).Tag = .AbsolutePosition
i = i + 1
.MoveNext
Loop
End With

BBanks said:
Hopefully I can ask this question so that someone understands my problem and
is properly motivated to help me.
I have a form that will include up to twelve records.
I am wanting to create buttons at the bottom of the form that only show up
when a new record is created.
When this button is clicked, it should go its corresponding record.
I also want the name of the button to reflect the DeviceID that is
co-located in the same form.
And finally, I want a button for every record that has data to show when the
form is opened.
I am fairly new to VB and know a very limited amount. If this makes me a
useless piece of trash, I am sorry.

On behalf of the entire community of users in this newsgroup, I apologize
for not trying to address your question earlier. You are not a pile of trash
for asking a question. Most users here are just trying to improve their
skills and everyone who spends time to answer questions does so for free;
sometimes questions slip through.
Barry
 
B

BBanks

It works great, can I ask you a couple questions?
What does the Me.Controls("cmd" & i).Tag = .AbsolutePosition do?
Also, how do I make a new button appear if I add an additional record?

Thanks again. It was nice to finally get an answer and so promptly as well.
 
B

Barry Gilbert

BBanks said:
It works great, can I ask you a couple questions?
What does the Me.Controls("cmd" & i).Tag = .AbsolutePosition do?
..AbsolutePosition returns the index of the selected record in the recordset,
starting at 0. For example, the fourth record down has an absoluteposition of
3.

Each control has a tag property that can be used to store any information
for use later. You can see this on the Other tab of the properties sheet. In
this case, I'm storing the absolute position value in each button's tag
property. The part that says
Me.Controls("cmd" & i)
is a way of looping through the controls collection to access all the
command buttons. If you step the code, you'll see that the first time through
the loop, this evaluates to cmd1, the second time to cmd2, etc. This while
thing is a funky way to do dynamic controls.
Also, how do I make a new button appear if I add an additional record?

In the form's AfterInsert event, put:

Form_Load

This will re-run the code and light up the new button (I think :)).
Thanks again. It was nice to finally get an answer and so promptly as well.

Glad I could help.

Barry
 
B

BBanks

Well I thought everything was working great...
I didn't think it would matter but this form is actually a subform. So now
when I go to a new record in the main form, it keeps the buttons from the
previous record on the subform. Also, I was not able to get it to show a new
button after putting in a new record on the subform using "form_load". I
apologize for the limited info on the first posting and being a complete nag.
I didn't realize all the interworkings. hopefully you can help me with this
new and bigger problem. Thanks.
 
B

Barry Gilbert

BBanks said:
Well I thought everything was working great...
I didn't think it would matter but this form is actually a subform. So now
when I go to a new record in the main form, it keeps the buttons from the
previous record on the subform. Also, I was not able to get it to show a new
button after putting in a new record on the subform using "form_load".

Instead of just calling Form_Load, you need to reference it from the parent
form like this:
Me.MySubformContainer.Form.Form_Load

where MySubformContainer is the name of the control on the parent form that
contains the subform. This is usually the same as the name of the subform.
I apologize for the limited info on the first posting and being a complete nag.

No problem. :)

Are the buttons still working to move you to the desired record?

Barry
 
B

BBanks

so on the parent form I need something like this?
Private Sub Form_AfterInsert()
Me.SbFrm_Container.Form.Form_Load
End Sub

Or should this be located in the subform's coding?
 
B

Barry Gilbert

As I understand you, the buttons are in the subform, but you want them loaded
up when the whole thing loads and after a new record is inserted in the main
form. If this is correct, then yes, the code should be in the main form's
AfterInsert event.

Barry
 
B

BBanks

Ok, I am really starting to feel stupid...
I am creating a db that shows all of our comm closets and has good/bad
entries for items that reflect the condition of that closet
I have a subform inside of that form that will include all of the
information for each of the network devices that are in that comm closet.
On the subform, I want to have a button show up for every device that I add
to the comm closet.
When I go to a new comm closet, I want it to start fresh with no buttons
because there will be no records.
When I go back to already created comm closets, I want it to show a button
for each of the network devices that I already added.

Does that make any more sense or am I still off in left field?
 
B

Barry Gilbert

It sounds like the records and the buttons are all within the subform.

When you click a record in the main form, you are choosing a comm closet.
This should automatically select device records in your subform based on the
Parent/Child link. Within the subform, you want a button for each record
(device) that takes you to that device. I think the original design, with all
the code in the subform, will work. Since your are inserting records into the
subform, the code that says Form_Load in the subform's AfterInsert event
should be sufficient.

If you're still stuck, feel semi-free to email (zipped) your mdb and I'll
take a look. My address is barry dot gilbert at hunterdouglas dot com.

Barry
 
B

Barry Gilbert

Ok. Got it.
You need to move the Form_Load statement into the Form_AfterInsert event
(not afterUpdate) of FRM_DeviceAudit. Then in the Form_Load event, add this
line:
..RecordsetClone.MoveFirst
before the Do Until statement.

I forgot to move the cursor back to the beginning of the recordsetclone each
time, so it never entered the loop after a new record was added.

Barry
 
Top