Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2002
    Posts
    5

    Unanswered: Access vs Micsrosoft SQL

    Have got this problem..using the same codes but have different results when i try it on Access and SQL server separately.

    Say there is a list of values inserted once a button is pressed in the database...

    5(last)
    8
    12
    13
    16
    20(first)

    How to i select the one that is inserted last into the database? In this case 5 is what i want. But i keep getting the earliest value! (20)

    I've tried the same codes for MS SQL but can get the lastest value...

    What is it that i need to change?

  2. #2
    Join Date
    Nov 2001
    Posts
    336
    You could possible make an extra field in your table to keep timestamp when the record was added to the table.
    Name this field, for example, AddDateTime and set default value to Now().
    Now your task would be much easier to accomplish.

    HTH,

  3. #3
    Join Date
    Feb 2002
    Posts
    5
    Thanks for your reply.
    This way there'll be 2 fields...
    So in my .asp what function for vbscript can i use to insert the same time inside?

  4. #4
    Join Date
    Nov 2001
    Posts
    336
    You may not have to change your vbscript at all. Just go to your backend (for example MDB file) and set default value for the field AddDateTime to Now().
    Now() is a VBA function and is allowed to be used in MS Access.

    HTH,

  5. #5
    Join Date
    Feb 2002
    Posts
    5
    But when i have 2 fields in the table i'll need to insert 2 values into it right? When i tried only to insert one, they'll prompt field values mismatch with the table.

  6. #6
    Join Date
    Nov 2001
    Posts
    336
    Hi,

    When you have 2 fields in the table and setup default values for them, then inserting only one field enforces the omitted field to take default value.

    MS Access Help File:

    You can use the DefaultValue property to specify a value that is automatically entered in a field when a new record is created. For example, in an Addresses table you can set the default value for the City field to New York. When users add a record to the table, they can either accept this value or enter the name of a different city.

    Notes

    The DefaultValue property doesn't apply to check box, option button, or toggle button controls when they are in an option group. It does apply to the option group itself.


    The DefaultValue property applies to all table fields except those fields with the data type of AutoNumber or OLE Object.
    Setting

    The DefaultValue property specifies text or an expression that's automatically entered in a control or field when a new record is created. For example, if you set the DefaultValue property for a text box control to =Now(), the control displays the current date and time. The maximum length for a DefaultValue property setting is 255 characters.

    For a control, you can set this property in the control's property sheet. For a field, you can set this property in table Design view (in the Field Properties section), in a macro, or by using Visual Basic.

    In Visual Basic, use a string expression to set the value of this property. For example, the following sets the DefaultValue property for a text box control named PaymentMethod to "Cash":

    Forms!frmInvoice!PaymentMethod.DefaultValue = """Cash"""Note To set this property for a field by using Visual Basic, use the ADO DefaultValue or use the DAO DefaultValue property.

    Remarks

    The DefaultValue property is applied only when you add a new record. If you change the DefaultValue property, the change isn't automatically applied to existing records.

    If you set the DefaultValue property for a form control that's bound to a field that also has a DefaultValue property setting defined in the table, the control setting overrides the table setting.

    If you create a control by dragging a field from the field list, the field's DefaultValue property setting, as defined in the table, is applied to the control on the form although the control's DefaultValue property setting will remain blank.

    One control can provide the default value for another control. For example, if you set the DefaultValue property for a control to the following expression, the control's default value is set to the DefaultValue property setting for the txtShipTo control.

    =Forms!frmInvoice!txtShipToIf the controls are on the same form, the control that's the source of the default value must appear earlier in the tab order than the control containing the expression.

Posting Permissions

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