0

I have two forms: transfert Form with its subform and intransfert Form. I am using

DoCmd.OpenForm "intransfert", , , , acFormAdd, acDialog, Me!Text83 

(where text83 is =[transfertasubform].[Form]![transfertadetailid] under

Private Sub Command78_Click() 

in transfet form and

Private Sub Form_Load() On Error Resume Next If Me.NewRecord Then Me!trnrin = Me.OpenArgs 

in intransfet form. intransfert form is based in transfertdetailquery. i wont to prevent passing text83 value more then one time

i tried to explain my problem and expect a help to prevent duplicates when used Arge

1 Answer 1

0

assuming trnrin is the name of a variable in your record source. assuming you mean that you want to avoid adding two records where trnrin has the same value and the user sent the same open args twice. assuming trnrin is also the name of a control in the detail section of the intransfert form.

'form load only runs when the form is opened so you have to close the form to pass new args 'but you can just move the same code to a button or whatever Private Sub IntransferForm_Load() If Len(Me.OpenArgs) > 0 Then Me.txtBoxintheHeader = Me.OpenArgs 'the load event is the right place to set controls 'most of this code is to check if there is already an instance where trnrin = the OpenArgs in the record source Dim lookedupArgs As String lookedupArgs = Nz(lookedupArgs = DLookup("trnrin", "MyTable", "trnrin = " & "'" & Me.OpenArgs & "'"), "ValuethatisneveranArg") If lookedupArgs = "ValuethatisneveranArg" Then 'Debug.Print "trnrin = '" & Me.OpenArgs & "'" 'note the string delimiters 'Me.trnrin = Me.OpenArgs 'this surprisingly works but will break easily and doesn't handle complex cases Dim rs As Recordset Set rs = Me.Recordset 'if recordset is bound to a table then table will also be updated. 'you can also bind to the table directly but you may need to call me.requery to show the changes rs.AddNew rs!trnrin = Me.OpenArgs rs.Update End If End If End Sub 
Sign up to request clarification or add additional context in comments.

2 Comments

it's my fault i didn't explain it well: i have two forms Form1 and Form2. on the Form1: Private Sub btn_Click() ,DoCmd.OpenForm "Form2", , , , acFormAdd, acDialog, Me!Text83, on the Form2:Private Sub Form_Load() If Me.NewRecord Then Me!trnrin = Me.OpenArgs. i Wont to prevent the user sent the same text83(text83 is unique number) twice
Your comment doesn't help me understand, but regardless, you can use the same concept to protect from entering the unique number twice. wherever you add the new record add the code to validate if the unique number has already been added and if the unique number has been added notify the user and don't add the record

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.