Form questions

G

Guest

Hi, I have 2 forms. Form A and Form B. They both have 2 fields called
"Company" and "Registration Number". I know it's possible to automatically
have the one of the fields filled up in Form B when details have been input
in Form A. What I want to know whether it's possible to have more than 1
field being filled up automatically?.
Below are the codes for Form A

Private Sub Person_Details_Click()
Dim strOpenArgs As String
Dim strCriteria As String
Dim strOpenArgss As String
Dim strCriterias As String
Dim strFormName As String
On Error GoTo Proc_Error

strFormName = "Person Details"
strCriteria = "[Company] = '" & Me![Company] & "'"
strOpenArgs = Me![Company]
DoCmd.OpenForm strFormName, WhereCondition:=strCriteria, OpenArgs:=strOpenArgs


Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in Person_Details_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub
-------------------------------------------------------------------------

Below are the codes for Form B

Private Sub Form_Open(Cancel As Integer)
Const Quote As String = """"
If Me.OpenArgs & "" <> "" Then
Me![Company].DefaultValue = Quote & Me.OpenArgs & Quote

End If

End Sub
 
K

Ken Snell \(MVP\)

Create a delimited string for the OpenArgs value, then parse it in the
second form:

Private Sub Person_Details_Click()
Dim strOpenArgs As String
Dim strCriteria As String
Dim strOpenArgss As String
Dim strCriterias As String
Dim strFormName As String
On Error GoTo Proc_Error

strFormName = "Person Details"
strCriteria = "[Company] = '" & Me![Company] & "'"
strOpenArgs = Me![Company] & "|" & Me![Registration Number]
DoCmd.OpenForm strFormName, WhereCondition:=strCriteria,
OpenArgs:=strOpenArgs


Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in Person_Details_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub
-------------------------------------------------------------------------

Below are the codes for Form B

Private Sub Form_Load()
Dim varOpenArgs As Variant
Const Quote As String = """"
If Me.OpenArgs & "" <> "" Then
varOpenArgs = Split(Me.OpenArgs, "|")
Me![Company].DefaultValue = Quote & varOpenArgs(0) & Quote
Me![Registration Number].DefaultValue = Quote & varOpenArgs(1) & Quote

End If

End Sub


Note: You should not use the Open event of the Form to do this, however,
because not all fields and controls are available to the VBA code during the
Open event. Better that you use the form's Load event to run the code in the
second form.
 
G

Guest

Thank you for your help, Ken!

Ken Snell (MVP) said:
Create a delimited string for the OpenArgs value, then parse it in the
second form:

Private Sub Person_Details_Click()
Dim strOpenArgs As String
Dim strCriteria As String
Dim strOpenArgss As String
Dim strCriterias As String
Dim strFormName As String
On Error GoTo Proc_Error

strFormName = "Person Details"
strCriteria = "[Company] = '" & Me![Company] & "'"
strOpenArgs = Me![Company] & "|" & Me![Registration Number]
DoCmd.OpenForm strFormName, WhereCondition:=strCriteria,
OpenArgs:=strOpenArgs


Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in Person_Details_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub
-------------------------------------------------------------------------

Below are the codes for Form B

Private Sub Form_Load()
Dim varOpenArgs As Variant
Const Quote As String = """"
If Me.OpenArgs & "" <> "" Then
varOpenArgs = Split(Me.OpenArgs, "|")
Me![Company].DefaultValue = Quote & varOpenArgs(0) & Quote
Me![Registration Number].DefaultValue = Quote & varOpenArgs(1) & Quote

End If

End Sub


Note: You should not use the Open event of the Form to do this, however,
because not all fields and controls are available to the VBA code during the
Open event. Better that you use the form's Load event to run the code in the
second form.
--

Ken Snell
<MS ACCESS MVP>




Firz said:
Hi, I have 2 forms. Form A and Form B. They both have 2 fields called
"Company" and "Registration Number". I know it's possible to automatically
have the one of the fields filled up in Form B when details have been
input
in Form A. What I want to know whether it's possible to have more than 1
field being filled up automatically?.
Below are the codes for Form A

Private Sub Person_Details_Click()
Dim strOpenArgs As String
Dim strCriteria As String
Dim strOpenArgss As String
Dim strCriterias As String
Dim strFormName As String
On Error GoTo Proc_Error

strFormName = "Person Details"
strCriteria = "[Company] = '" & Me![Company] & "'"
strOpenArgs = Me![Company]
DoCmd.OpenForm strFormName, WhereCondition:=strCriteria,
OpenArgs:=strOpenArgs


Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in Person_Details_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub
-------------------------------------------------------------------------

Below are the codes for Form B

Private Sub Form_Open(Cancel As Integer)
Const Quote As String = """"
If Me.OpenArgs & "" <> "" Then
Me![Company].DefaultValue = Quote & Me.OpenArgs & Quote

End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top