Link to home
Start Free TrialLog in
Avatar of TIgerV
TIgerVFlag for United States of America

asked on

Use a second form to fill entries in the first form

I have an events log that my employees use daily to record what gets done.
I would like to have a button bring up a second form, that gives options for 'canned' entries.  Examples of a Canned entry would be: "Closed for Lunch" or "Primary Staff meeting".
Currently, I have a database that offers these buttons at the bottom, but they take up an excessive amount of room and I want to instead call them up by using a button.
My issues are 2 fold:
1.  On my current database (I'm scrapping it and starting over), the buttons are labeled automatically by a value in the table containing the entries.  Table includes these fields:  [ID], [Entry text], [short text].  For some reason, this code isn't working:
Private Sub FillOptions()
Const NUMBUTTONS = 16
 Dim seldata As String
 Dim num As Integer
 Dim dbs As Database
 Dim label As Recordset
 Set dbs = CurrentDb()
 seldata = "SELECT * FROM [tbl_Canned Entries]order by [ID];"
 Set label = dbs.OpenRecordset(seldata)
 While (Not (label.EOF))
   Me("toggle" & label![ID]).Caption = label![Short Text]
   label.MoveNext
   Wend
   label.Close
   dbs.Close
   
End Sub

Open in new window


The second piece is what is the easiest way to get the text from the table to post?   a button that says "USE THIS"?
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or you could create a shortcut menu and use that.

Here are a couple of articles I wrote about using shortcut menus:
Understanding and using CommandBars (ShortCut menus), Part 1
Understanding and using CommandBars, Part II (Creating your own)
Avatar of TIgerV

ASKER

Thank You!

Dale- I am sure, as usual, your solution was excellent, but I'm just not VB Savvy enough.
Avatar of TIgerV

ASKER

This is working fine, however-
   I have moved the source form into a subform.  
I have:
Forms("frm_log entries").entry = Me.Litsbox4.Column(2)

However now "Frm_log entries" is a subform in "Frm_log page".   How do I direct the update to the subform?
To refer to a subform, you refer first to the Subform CONTROL, then the Form object, then the property/method:

Forms("frm_Log entries").SubFormCONTROL.Form.Entry = Me.Litsbox4.column(2)

SubFormCONTROL is the Subform Control that's on the main form. It may or my not be named the same as the form you're using as a Subform.
Assuming that the subform control NAME is also "frm_log entries", the syntax would look like:

Forms("Frm_log page").[frm_log entries].Form.Entry = me.listbox4.column(2)

But it might be easier than that, depending on where listbox4 is located.  If listbox4 is located on "frm_log page" then the syntax would simply be:

me.[frm_log entries].form.Entry = me.listbox4.column(2)

Also, I would strongly recommend that you:
1.  stop putting spaces in your form or control names.  SPACES and special characters are bad!!!
2.  adopt a naming convention for all of your database objects and the controls on them.  this takes a little longer to actually go through your forms and reports and rename all of your controls so that the NAME property of all of the controls indicates the type of control (lbl_Date, txt_Date, cbo_Date, lst_Something).  This accomplishes two things.
    a.  it makes it easier to read your code and determine what control you are referring to (what is listbox4 off the top of your head?).
    b.  it distinquishes your controls from the fields on the form.  Yes, you can name your FirstName text box FirstName (Access actually does this for you).  But when you see me.FirstName in your code are your referring to the control, or to the value of the underlying field?  Better to have a control named txt_FirstName.