Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2003
    Posts
    11

    Unanswered: Access 2002 programming

    HELP!

    I set up a hazardous material table named tblReceivals with the following fields: MaterialName, QtyReceived, QtyDisposed, QtyRemained, etc.

    I also set up a data entry form named frmReceivals where the user can populate the QtyReceived field for adding a new record. The QtyRemained field is not on this form.

    How can I assign the input QtyReceived value to the QtyRemained value (these two fields should have the same values) in a new added record, using a frmReceivals event procedure?

    THANKS!

  2. #2
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Re: Access 2002 programming

    Originally posted by diensatthan
    HELP!

    I set up a hazardous material table named tblReceivals with the following fields: MaterialName, QtyReceived, QtyDisposed, QtyRemained, etc.

    I also set up a data entry form named frmReceivals where the user can populate the QtyReceived field for adding a new record. The QtyRemained field is not on this form.

    How can I assign the input QtyReceived value to the QtyRemained value (these two fields should have the same values) in a new added record, using a frmReceivals event procedure?

    THANKS!
    Using Access you have 2 ways to populate a table by using a form.
    The first is by using bounded controls (this means that the fields of the table are assigned to for example a textbox).
    I used this way in the beginning, but I didn't like it.
    Why ?
    Suppose you are entering data into textboxes on the form, but they're not all completed yet. When you swith to a subform, Access will already add the 'incomplete' record to the table because of autocommit.
    Therefore I prefer the second way.
    I do not assign my controls to a field (unbound controls)
    I fill in my data and only when pressing a buttun I will add the record to the table.

    Your table is like this :
    MaterialName, QtyReceived, QtyDisposed, QtyRemained

    Your form contains 3 textboxes :
    txtName, txtReceived, txtDisposed

    You can use this code :
    Code:
    public sub button_Click()
    
    Dim strSQL as String
    
    strSQL = 
    "INSERT INTO tblReceivals (MaterialName, QtyReceived, QtyDisposed, QtyRemained) " & _
    "VALUES (" & txtName.text & "," &  val(txtReceived.text) & "," & val( txtDisposed.text) & "," &  val(txtReceived.text) & ")"
    
    Docmd.runSQL strSQL
    
    end sub
    If you really want to use the first method you can put an invisible textbox on the form for QtyRemained.
    In the QtyReceived_Change - event you write

    Code:
    txtRemained.text = txtReceived.text
    Hope this will help you out.
    Last edited by artemide; 04-28-03 at 03:32.

Posting Permissions

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