Results 1 to 11 of 11
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Thumbs up Setting default

    I am using this to set a default date (on the fly for the user) I know I can go into the field properties and change it, but I don't want the user in there.



    Private Sub NIE_Def_Click()
    Dim Prompt As String
    Dim NIE_Ans
    Prompt = "Please enter the current NIE as '##.#'"
    NIE_Ans = InputBox(Prompt, "NIE Default")
    If IsNumeric(NIE_Ans) Then
    Me.NIE.Value = NIE_Ans
    Me.NIE.DefaultValue = Chr(34) & NIE_Ans & Chr(34)
    End If
    End Sub

    I am getting the error on the .DefaultValue = as Method or data member not found.

    Table: Change_Request
    Field: NIE (Double, General, Auto) Lookup =textbox

    Form: Start
    Toggle Button Name: NIE_DEF

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    The field is named NIE. Is the textbox the same name?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    The button name is NIE_Def to get the popup. I'd gather NIE_Ans is the name of the input field (text box on the popup). There is no actual text box per se and the pop answer should look at the NIE field in the Change Request Table.

    I don't think I really need the checking routing if it is numeric, so I took out the If then statement.

    Private Sub NIE_Def_Click()
    Dim Prompt As String
    Dim NIE_DEF
    Prompt = "Please enter the current NIE as ##.#"
    NIE_DEF = InputBox(Prompt, "Default NIE")
    Me.NIE.Value = NIE_DEF Me.NIE.DefaultValue = Chr(34) & NIE_DEF & Chr(34)
    End Sub

    It still stops at the red above. If I am researching correctly, the .DefaultValue refers to a ComboBox? I can take out the .DefaultValue line but it doesn't affect the NIE field in the table at all.

    I've tried = """" & NIE_DEF & """" also. Do I need to put some kind of code in the properties default box? Maybe a DLookUp or Dlast?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    The box of an InputBox popup does not have a name. It is not a distinct element that can be addressed.

    If you want the InputBox to display a default value when it pops up, then use the Default argument of InputBox:

    Me.NIE = InputBox("Please enter the current NIE as ##.#", "Enter NIE", some default value here)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June7,
    I put the following in:
    Private Sub NIE_Def_Click()
    Me.NIE = InputBox("Please enter the current NIE as ##.#", "Enter NIE", NIE)
    DoCmd.RunCommand acCmdSaveRecord
    End Sub

    When I click the button, the inputBox pops up with the original default value ghosted and ready for overwrite. The issue is, it doesn't save it to the current record, but to record #1.

    I am projecting that what I enter will change the "Some Default Value Here" part of the equation. What I am looking for is that the value will change from the current record onwards until the default value is changed again.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    That code should edit whatever record has focus on the form. If that is not record number 1, what record is it?

    You are referencing the field as the source of default value. If this is a new record row, then that field should not have a value. Doesn't make sense to me.

    If you want value carried forward to new record, that requires programmatically changing the DefaultValue property of a textbox in the textbox AfterUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I don't know why it works with only the first record. I would have thought it would work with the next new record. I should say that the record is made with a new form. But one would think it wouldn't matter if the source table field has been changed, it wouldn't matter the form. I went with it and tried this and it seems to work with it changing the first record.

    Private Sub Form_Current()
    Dim tmpNIE As Double
    tmpNIE = DLookup("NIE", "Change Request")
    Me.NIE=tmpNIE
    End Sub

    The issue with that is if a user goes back to an old record and edits it. It will change that records NIE field to the current setting in filed 1.

    What textbox are we talking about? I even tried the filter route that you showed me for the CR_Numbers. That didn't work. I don't have a clue as to why it wouldn't go to the current record.

    Attached is the latest version.

    I have put the NIE field in the Board Change Request form so that I can see the changes in NIE, if there was any made. The Start form has the Toggle button to start the Input box.

    NIE 15.2 CR.zip

  8. #8
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Quote Originally Posted by June7 View Post
    that requires programmatically changing the DefaultValue property of a textbox in the textbox AfterUpdate event.
    THIS is exactly what I am trying to do. What if there is no text box on the form(s) I am using which refere to NIE?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Why not have textbox bound to field?

    If there is no textbox then cannot set DefaultProperty.

    Exactly what steps do I follow to replicate the issue you describe? What buttons do I click and what data do I enter?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June7,
    Open the dB, select "NIE default" toggle, fill in the box with a number such as 23.3. Hit enter or OK, then select Board request. Go to last record, hit next record fill in the "Change Requested" box with a few characters and select save, then close. Go to the Change Request Table you will see the first row filled in with "23.3, and the record you filled in with a blank.

    I think I may need to add in a doDoCmd.GoToRecord , , acNewRec when I select the NIE Default button.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    The popup box input is saved to the record of the Start form. The popup has nothing to do with record on the Board Change Request form.

    Yes, if you want to create a new record via the Start form, then move to new record row then open the popup.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting a default value of 0 in a query
    By Access_Novice in forum Queries
    Replies: 1
    Last Post: 10-23-2014, 11:41 PM
  2. Setting default value to zero in form box?
    By dekhelia in forum Forms
    Replies: 6
    Last Post: 10-17-2013, 08:53 AM
  3. Automaticly Setting Default Value
    By swicklund in forum Forms
    Replies: 5
    Last Post: 06-17-2013, 08:08 AM
  4. Setting default vaulue?
    By djclntn in forum Forms
    Replies: 17
    Last Post: 04-12-2012, 11:20 PM
  5. Setting the Default Value and Proper Case Example
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-27-2010, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums