Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2003
    Location
    Japan/California
    Posts
    68

    Unhappy Unanswered: Insert Default Value In New Record

    Hello,
    im working on a form in access 2000.

    ive got a system where the records need to duplicate a lot. the way im doing it is by setting the default values for the next record to whatever value was entered in the previous record (with the exception of the date field, which i currently have the default value set to datefield.value + 1).

    thats working fine, but because its on an afterupdate event i still have to update something to make the values copy down and create a new record.

    what i want to do is make the record update automatically with a gotfocus event (or a double click or something) so users can just tab through the form making new records everytime they get to the last column.

    heres the code i have so far:

    ///////////////////

    Private Sub form_afterupdate()
    Me.cboregion.DefaultValue = """" & Me.cboregion.Value & """"
    Me.cbocity.DefaultValue = """" & Me.cbocity.Value & """"
    Me.airline.DefaultValue = """" & Me.airline.Value & """"
    Me.date.DefaultValue = """" & Me.date.Value + 1 & """"
    Me.price.DefaultValue = """" & Me.price.Value & """"
    Me.type.DefaultValue = """" & Me.type.Value & """"
    End Sub

    ///////////////////

    and heres the code i tried but didnt work:

    ////////////////////

    Private Sub type_Enter()
    Me![type] = Me.type.DefaultValue
    End Sub

    ////////////////////

    TIA

  2. #2
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465

    Re: Insert Default Value In New Record

    Originally posted by jonah9
    Hello,
    im working on a form in access 2000.

    ive got a system where the records need to duplicate a lot. the way im doing it is by setting the default values for the next record to whatever value was entered in the previous record (with the exception of the date field, which i currently have the default value set to datefield.value + 1).

    thats working fine, but because its on an afterupdate event i still have to update something to make the values copy down and create a new record.

    what i want to do is make the record update automatically with a gotfocus event (or a double click or something) so users can just tab through the form making new records everytime they get to the last column.

    heres the code i have so far:

    ///////////////////

    Private Sub form_afterupdate()
    Me.cboregion.DefaultValue = """" & Me.cboregion.Value & """"
    Me.cbocity.DefaultValue = """" & Me.cbocity.Value & """"
    Me.airline.DefaultValue = """" & Me.airline.Value & """"
    Me.date.DefaultValue = """" & Me.date.Value + 1 & """"
    Me.price.DefaultValue = """" & Me.price.Value & """"
    Me.type.DefaultValue = """" & Me.type.Value & """"
    End Sub

    ///////////////////

    and heres the code i tried but didnt work:

    ////////////////////

    Private Sub type_Enter()
    Me![type] = Me.type.DefaultValue
    End Sub

    ////////////////////

    TIA
    Use the sentence: DoCmd.RunCommand (acCmdSaveRecord)
    Saludos
    Norberto

  3. #3
    Join Date
    Jul 2003
    Location
    Japan/California
    Posts
    68

    NO GO

    Thanks for the help, but it didnt work. Nothing happened.
    im guessing that because only the default values are set and nothing was actually selected, Access is seeing the new record as blank and therefore not inserting anything.

    Any Ideas?

    I think what i want to do is mimic the effect of pressing CTL+ALT+Spacebar (insert default values) but do it through an event rather than pressing the keyboard.

  4. #4
    Join Date
    Jul 2003
    Location
    Japan/California
    Posts
    68

    Angry Strange

    Ok, after working on this awhile i finally got it to work, but when i closed my database and opened it again, it doesnt work anymore. is there something wrong with my code?:


    Private Sub cbo2_Enter()
    ' insert values into the current record equal to the default values for the record
    Dim sameprice As String
    sameprice = "" & Me!cboprice.DefaultValue & ""
    Me!cboprice.Value = Replace(sameprice, Chr(34), "", 1, -1, vbTextCompare)
    End Sub

  5. #5
    Join Date
    Jul 2003
    Location
    Japan/California
    Posts
    68

    Angry DblClick

    Argh,

    for some reason if i use the Double Click event it works fine. but why doesnt it do the same thing for the Enter or GotFocus events?

    my double click code looks like this:

    Private Sub cbo2_DblClick(cancel as integer)
    ' insert values into the current record equal to the default values for the record
    Dim sameprice As String
    sameprice = "" & Me!cboprice.DefaultValue & ""
    Me!cboprice.Value = Replace(sameprice, Chr(34), "", 1, -1, vbTextCompare)
    End Sub

  6. #6
    Join Date
    Jul 2003
    Location
    Japan/California
    Posts
    68

    Smile YES!

    hey folks,

    i finally got this working for anybody who wants to do the same thing, i think it makes data entry sooooo much smoother. now all you have to do is hold down the tab or enter key and it will continue copying records (while adding 1 day to the date) continuously. heres the code:


    Private Sub Form_AfterUpdate()
    Me.airport.DefaultValue = """" & Me.airport.Value & """"
    Me.cboregion.DefaultValue = """" & Me.cboregion.Value & """"
    Me.cbocity.DefaultValue = """" & Me.cbocity.Value & """"
    Me.airline.DefaultValue = """" & Me.airline.Value & """"
    Me.date.DefaultValue = """" & Me.date.Value + 1 & """"
    Me.cboprice.DefaultValue = """" & Me.cboprice.Value & """"
    Me.type.DefaultValue = """" & Me.type.Value & """"
    End Sub

    Private Sub type_GotFocus()
    Dim sameprice As String
    sameprice = "" & Me!cboprice.DefaultValue & ""
    Me!cboprice.Value = Replace(sameprice, Chr(34), "", 1, -1, vbTextCompare)

    Me.type.Requery

    End Sub

  7. #7
    Join Date
    Feb 2004
    Posts
    137
    Actually, all you have to do is place the AfterUpdate code in the BeforeUpdate event, like this:

    Private Sub Form_BeforeUpdate(Cancel As Integer)Me.airport.DefaultValue = """" & Me.airport.Value & """"
    Me.cboregion.DefaultValue = """" & Me.cboregion.Value & """"
    Me.cbocity.DefaultValue = """" & Me.cbocity.Value & """"
    Me.airline.DefaultValue = """" & Me.airline.Value & """"
    Me.date.DefaultValue = """" & Me.date.Value + 1 & """"
    Me.cboprice.DefaultValue = """" & Me.cboprice.Value & """"
    Me.type.DefaultValue = """" & Me.type.Value & """"
    End Sub

    Then you can delete the AfterUpdate code and the GotFocus code, because the BeforeUpdate event handles it all for you.

  8. #8
    Join Date
    Jul 2003
    Location
    Japan/California
    Posts
    68

    i dont think so

    i dont know if theres something else wrong with this, but when i tried what you said it didnt work. it still dropped the default values down to the new record, but just entering the new record wouldnt trigger the beforeupdate event. i had to change something or enter something in that record to get it to put the data into the table. this is why i needed the GotFocus code on the last column, so that just by tabbing throught you could add records, without having to manually enter anything.

    thanks for the suggestion though

Posting Permissions

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