Question

I have an Access 2003 database that will be handling RMA (Return Material Auth) information (date, RMA Nbr, Evaluation, ship date, Items on the RMA, etc). In this Access database I have three forms:

  • Add RMA (Adds a new RMA to the database with no items. This form (will have) a subform on it listing all the items on the RMA added so far)
  • View RMA (Views information on existing RMA's in the database, with all the items on each RMA in a subform)
  • Add Item to RMA (since each RMA can have more than one different type of item being returned, I have a form dedicated to adding a new item to RMAs. After each entry, the form clears itself and allows more entries)

The 'Add RMA' and 'Add Item' to RMA forms have all unbound fields (they're designed to accept new input and only INSERT INTO the database when a button is pushed.

The 'Add Item to RMA' form has five fields, all unbound. The actual form is not referencing the information from the database at all. One of the five fields is the RMA Number.

The 'New RMA' and 'View RMA' forms have a button that is supposed to open the 'Add Item to RMA' form. I would like said button to open the 'Add Item to RMA' form with the RMA Number field pre-filled with the RMA Number from the previous screen. Each field on each form has the name "RMANbr".

On the command button in the 'View RMA' form I have the the following code in the "On Click" event but it does not seem to be working. The 'Add RMA to Item" field shows up blank:

Private Sub AddItemtoRMA_Click()
  DoCmd.OpenForm "Add Item to RMA", , , "RMANbr = " & Me!RMANbr
End Sub

Keep in mind the fields are unbound.

So, I need code that will automatically fill in the unbound RMANbr field on the 'Add Item to RMA' form with the RMANbr field from the 'Add RMA' and 'View RMA' forms.

I would also like to have the subforms in the 'Add RMA' and 'View RMA' listing all the items refresh/requery after each item is added through the 'Add Item to RMA' form (when the button is pushed). I've tried

RMA Inforation.Requery
Add RMA.Requery

with no success. No refresh, no errors, nothing.

Can this be done with code?

Was it helpful?

Solution

Not sure how well I followed the description, but it seems you might take advantage of the OpenArgs parameter with OpenForm. (Your existing code uses the WhereCondition parameter, but that is meaningless for an unbound form.)

OpenArgs is the seventh parameter to OpenForm. If I counted commas correctly, this could work:

DoCmd.OpenForm "Add Item to RMA", , , , , , Me!RMANbr

However, I would use the option's name to avoid counting commas.

DoCmd.OpenForm "Add Item to RMA", OpenArgs:=Me!RMANbr

Then in the target form's load event, you can move to the new record and use the OpenArgs value in the text box which holds RMANbr (I guessed the text box name is txtRMANbr).

Private Sub Form_Load()
    DoCmd.GoToRecord acDataForm, , acNewRec
    If Not IsNull(Me.OpenArgs) Then
        Me.txtRMANbr = Me.OpenArgs
    End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top