passing a value from one form to another

Terkpeh1990

Registered User.
Local time
Today, 04:57
Joined
Nov 18, 2017
Messages
24
i have a personnel form and a bank form . these two forms are both have a mandatory field called "Staff id" . is there a way i can pass the staff id on the personnel form to the bank form automatically once the user enters it in the personnel form .

Can anyone please help me with the vba code. Thank u
 
the second form ( Bank form ) only opens after the first form (personnel form) closes
 
So how is the either the personnel form closed, or the bank form opened?
Is it by a command button (VBA)or a macro?

If it's VBA post up the code of both events.
 
Where is Staff_ID stored? When you open the other form, how do you know which Staff_ID you want?
 
Dim Response As Integer

Response = MsgBox("Do You want to save and procced to Bank Details ?", vbYesNo + vbInformation, "AUDIT SERVICE RETIREMENT MANAGEMENT SYSTEM")
If Response = vbYes Then

RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec

DoCmd.OpenForm "BANK FORM"
DoCmd.Close acForm, "PERSONNEL FORM"

Else
Me.Undo
End If

that's the code . is just a code to close the personel form and open the bank form.
i would like to get the current staff id of the personnel form on the bank form immediately it opens .
Can anyone please help me.
 
It's still not clear what you are doing. Is the bank form being opened for new data entry and you want it to default to the same StaffID? Or do you want it to open to a specific record of StaffID?

the OpenForm method has several arguments
Code:
expression. OpenForm (FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

To open to a specific record you would use the whereCondition argument.
To pass the StaffID as the default value of the StaffID field in the bank form you can pass it in the OpenArgs argument and in the Bank form set the default value of the staffID field equal to OpenArgs (=OpenArgs)

You should eliminate the spaces in your field names.
DoCmd.GoToRecord , , acNewRec - Not sure why you have this but I suspect it isnt needed.
 
Given the code you posted in #7, the "OpenArgs" idea suggested by Minty seems to be the simplest option.

https://msdn.microsoft.com/en-us/vba/access-vba/articles/docmd-openform-method-access

In this case, you would perhaps pass your StaffID via OpenArgs, which is the 7th argument of the DoCmd.OpenForm call. If this is a number, you might wish to pass it as CStr(StaffID) but if it is a text field, just pass it as-is.

Then in the form being opened, during the Form_Open event, you can test for the Me.OpenArgs property to be blank or not and if not, use a sequence of DoCmd.FindRecord followed by DoCmd.GoToRecord to position yourself.
 

Users who are viewing this thread

Back
Top Bottom