+ Reply to Thread
Results 1 to 9 of 9

Enhanced Data Form - Setting Default Values

Hybrid View

kgreave1 Enhanced Data Form - Setting... 07-12-2012, 11:50 AM
JapanDave Re: Enhanced Data Form -... 07-12-2012, 11:53 AM
kgreave1 Re: Enhanced Data Form -... 07-12-2012, 12:07 PM
royUK Re: Enhanced Data Form -... 07-12-2012, 01:34 PM
kgreave1 Re: Enhanced Data Form -... 07-12-2012, 03:49 PM
royUK Re: Enhanced Data Form -... 07-13-2012, 02:30 AM
kgreave1 Re: Enhanced Data Form -... 07-13-2012, 12:00 PM
kgreave1 Re: Enhanced Data Form -... 07-13-2012, 12:46 PM
royUK Re: Enhanced Data Form -... 07-13-2012, 01:58 PM
  1. #1
    Registered User
    Join Date
    06-22-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    18

    Enhanced Data Form - Setting Default Values

    I know that it is possible through talking with people, so my question is pretty simple: How do you set an Enhanced Data Form (like the J-walk Enhanced Data Form) to put a "default" value for new entries?

    I have set the data form up to automatically insert a new row and new entry. I want that insert to automatically populate a default value for some of the fields. However since there is no defining of the variables manually, I am not sure what call those variables when trying to define the default values. Typically, I would use something like this:

    Myvariable.value = "default value"

    but since there is no defining "myvariable", I am not sure how to do it.

    Any thoughts/ideas?

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Enhanced Data Form - Setting Default Values

    Is this a user form?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    06-22-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enhanced Data Form - Setting Default Values

    In short, yes it is a User Form (in that it is loaded through "Private Sub UserForm_Initialize().

    The Form itself is an add-in that has been written in VBA. It acts the same as the Excel Data Form (in the way it populates), but has the added benefit of being customizable. Basically, it will look at the "database" of the selected cell. Then it looks to the headers of the data base and automatically creates a User Form like Pop-up for you to enter new data.

    I would prefer not to post the code, as there is a key you have to purchase to view the coding on the form, but if it is required to answer the question, I will try to post what I can without causing any issues.
    Last edited by Cutter; 07-13-2012 at 08:12 AM. Reason: Removed whole post quote

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Enhanced Data Form - Setting Default Values

    Don't post the code because that would then make john Walkenbach's code public.

    Maybe something like

    Const MyValue as String= "Test"
    
    Me.TextBox1.Value= MyValue
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    06-22-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enhanced Data Form - Setting Default Values

    I tried this and ran into some problems. I was trying to change the third combo box, which is filled by using a named range, and got this error both times:
    "Compile Error: Method or Data member not found"

    I tried both of the following:
    Me.ComobBox3.Value = "Default Value"
    Me.Service_Type.Value = "Default Value"

    Where Service_type is the named range that works to fill the combobox.
    Last edited by Cutter; 07-13-2012 at 08:11 AM. Reason: Removed whole post quote

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Enhanced Data Form - Setting Default Values

    All your code is doing is putting "Default Value" as the value into the combobox.

    You cannot use Me to add it to the range because the range is not an object on the userform

    You might need

    Range(Service_Type.Value).offset(1,0).Value="Default Value"
    Note you are using a String not a Variable!

  7. #7
    Registered User
    Join Date
    06-22-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enhanced Data Form - Setting Default Values

    That is what I am trying to do right now though, add a default value into the combo box. For example, I was Service_Type to always show "Consulting Service" when form opens. I just wanted to clarify in case it wasn't clear.

    I think the real problem I am facing is that I can't figure out what the code is naming things.
    Here are my column headers: IC_Name, Opportunity, Work Order Number, Cost Center, Service_Type, Department, Hours used per week
    Where IC_Name, Opportunity, Service_Type, and Department have named ranges that cause them to be comboboxes.

    Here is the coding that is populating them. I cut out as much as I could, but thought this was necessary to help with discovering the names:
    Set NewLabel = CurrentFrame.Controls.Add("forms.label.1")
                With NewLabel
                    .Caption = Application.WorksheetFunction.Clean(DatabaseRange.Cells(1, j)
                End With
                ModifiedName = Application.Substitute(NewLabel.Caption, " ", "_")
                
                If NameHasData(ModifiedName) Then
                    Set NewControl = CurrentFrame.Controls.Add("forms.combobox.1")
                    ComboBoxOptions = UNIQUEITEMS(Worksheets(Range(ModifiedName).Parent.Name).Range(ModifiedName))
                    If IsArray(ComboBoxOptions) Then NewControl.List = ComboBoxOptions
                Else
                    'Add a TextBox
                    Set NewControl = CurrentFrame.Controls.Add("forms.textbox.1")
                End If
                With NewControl
                    .Top = VerticalPosition
                    .Left = FieldWidth + 6
                    .Height = 16
                    .Font.Size = 8
                    .Tag = "EntryControl"
                End With
                VerticalPosition = VerticalPosition + 18 'increment
            Next j

    Here is a picture of what it looks like. It is creating it the way I want it, just can't figure out the names of the combobox/texbox to set default values
    DataEntryFormPic.jpg
    Last edited by kgreave1; 07-13-2012 at 12:21 PM.

  8. #8
    Registered User
    Join Date
    06-22-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enhanced Data Form - Setting Default Values

    I did it!!!!!

    I used

    Frame1!combobox1.Value = "Test"
    and it works!

    I'm finally catching on to this VBA stuff!!!

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Enhanced Data Form - Setting Default Values

    Glad you got there and thanks for the rep

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1