Relating two forms

  • Thread starter Thread starter George Papadopoulos
  • Start date Start date
G

George Papadopoulos

Greetings everybody

I am building a database based on Microsoft Access. The database stores
'Technician report sheets info'. I have these two tables, the first stores
information about 'technician visit' such as technician code, serviced
company name, e.t.c. The second table stores various 'spare parts' used in
the repairing. This table has a foreign key named 'technician visit code'
which is unique for every visit of a technician and relates the above
forementioned tables.
Correspondingly, there are two forms for these tables. I need to have a
button on the first form (techician visit) such that when it is pressed, the
second form opens but the foreign key of the second table (spare parts)
takes the value of 'technician visit code' from the first form.
I have used the below code :

Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

for the button event handler. When I press the button though, I get the
error 'Object doesn`t support the property or method'.

Am I missing something?
 
George,

The suspect line is:
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code
whereby you are addressing the property Code of control Visit Code in both
forms... well, no such property exists, thus the error message. Try this:


Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

varvc = Me.[Visit Code]

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code] = varvc

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

You will notice that I have removed reference to Code property, which does
not exist; reference to the control itself addresses its value property by
default.
Also, I have used an extra line and variable to read the value of visit code
before the second form is opened. As is in your code, the active form when
you get to that line is the second (already opened), so Me.[Visit Code] will
return a glorious null there!

HTH,
Nikos
 
I tried using your code. First I would like to clarify a couple of things.
The two 'Visit Code' fields on the two forms are bounded text boxes. So I
modified your code by accessing the Text method of each text box. (e.t.c.
varvc = Me.[Kwdikos episkeyhs].Text). Now, when I execute the code, by
pressing the button, I get the error 'You can`t reference a property or
method unless the control has focus'.
I had to change the references to the controls on the second form by
qualifying by 'Me' instead of [Forms].stDocName.
Code:
.Text
(Me.[Code].Text). Now the code works but I get yet another error.
'This property is read only and can`t be set'

Thanks for your help

George
[QUOTE="Ï "Nikos Yannacopoulos"]
George,

The suspect line is:
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code
whereby you are addressing the property Code of control Visit Code in both
forms... well, no such property exists, thus the error message. Try this:


Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

varvc = Me.[Visit Code]

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code] = varvc

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

You will notice that I have removed reference to Code property, which does
not exist; reference to the control itself addresses its value property by
default.
Also, I have used an extra line and variable to read the value of visit code
before the second form is opened. As is in your code, the active form when
you get to that line is the second (already opened), so Me.[Visit Code] will
return a glorious null there!

HTH,
Nikos

[QUOTE="George Papadopoulos"]
Greetings everybody

I am building a database based on Microsoft Access. The database stores
'Technician report sheets info'. I have these two tables, the first stores
information about 'technician visit' such as technician code, serviced
company name, e.t.c. The second table stores various 'spare parts' used in
the repairing. This table has a foreign key named 'technician visit code'
which is unique for every visit of a technician and relates the above
forementioned tables.
Correspondingly, there are two forms for these tables. I need to have a
button on the first form (techician visit) such that when it is pressed, the
second form opens but the foreign key of the second table (spare parts)
takes the value of 'technician visit code' from the first form.
I have used the below code :

Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

for the button event handler. When I press the button though, I get the
error 'Object doesn`t support the property or method'.

Am I missing something?
[/QUOTE]
[/QUOTE]
 
Could this be a problem originating from the fact that the text box is
bounded to a table?


Ï "George Papadopoulos said:
I tried using your code. First I would like to clarify a couple of things.
The two 'Visit Code' fields on the two forms are bounded text boxes. So I
modified your code by accessing the Text method of each text box. (e.t.c.
varvc = Me.[Kwdikos episkeyhs].Text). Now, when I execute the code, by
pressing the button, I get the error 'You can`t reference a property or
method unless the control has focus'.
I had to change the references to the controls on the second form by
qualifying by 'Me' instead of [Forms].stDocName.
Code:
.Text
(Me.[Code].Text). Now the code works but I get yet another error.
'This property is read only and can`t be set'

Thanks for your help

George
[QUOTE="Ï "Nikos Yannacopoulos"]
George,

The suspect line is:
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code
whereby you are addressing the property Code of control Visit Code in both
forms... well, no such property exists, thus the error message. Try this:


Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

varvc = Me.[Visit Code]

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code] = varvc

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

You will notice that I have removed reference to Code property, which does
not exist; reference to the control itself addresses its value property by
default.
Also, I have used an extra line and variable to read the value of visit code
before the second form is opened. As is in your code, the active form when
you get to that line is the second (already opened), so Me.[Visit Code] will
return a glorious null there!

HTH,
Nikos

[QUOTE="George Papadopoulos"]
Greetings everybody

I am building a database based on Microsoft Access. The database stores
'Technician report sheets info'. I have these two tables, the first stores
information about 'technician visit' such as technician code, serviced
company name, e.t.c. The second table stores various 'spare parts'[/QUOTE][/QUOTE] used[QUOTE]
in[/QUOTE] have[QUOTE]
a[QUOTE]
button on the first form (techician visit) such that when it is[/QUOTE] pressed,
the[QUOTE]
second form opens but the foreign key of the second table (spare parts)
takes the value of 'technician visit code' from the first form.
I have used the below code :

Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

for the button event handler. When I press the button though, I get the
error 'Object doesn`t support the property or method'.

Am I missing something?
[/QUOTE]
[/QUOTE]
[/QUOTE]
 
Hello,
I believe I have the same issue as George, but I am more of a beginne
with access and do not use program code. Is there a way to accomplis
what the code does using a more point-and-click approach?

Thank you,
Am
 
by accessing the Text method of each text box. (e.t.c.
varvc = Me.[Kwdikos episkeyhs].Text).
There is no such thing as a method for a given control! You probably mean
property, which is what Access intrprets your syntax to, thus the error
message. Remove the .Text part altogether:
varvc = Me.[Kwdikos episkeyhs]
Me.
Code:
should do the job.

HTH,
Nikos

[QUOTE="George Papadopoulos"]
I tried using your code. First I would like to clarify a couple of things.
The two 'Visit Code' fields on the two forms are bounded text boxes. So I
modified your code by accessing the Text method of each text box. (e.t.c.
varvc = Me.[Kwdikos episkeyhs].Text). Now, when I execute the code, by
pressing the button, I get the error 'You can`t reference a property or
method unless the control has focus'.
I had to change the references to the controls on the second form by
qualifying by 'Me' instead of [Forms].stDocName.[Code].Text
(Me.[Code].Text). Now the code works but I get yet another error.
'This property is read only and can`t be set'

Thanks for your help

George
[QUOTE="Ï "Nikos Yannacopoulos"]
George,

The suspect line is:
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code
whereby you are addressing the property Code of control Visit Code in both
forms... well, no such property exists, thus the error message. Try this:


Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

varvc = Me.[Visit Code]

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code] = varvc

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

You will notice that I have removed reference to Code property, which does
not exist; reference to the control itself addresses its value property by
default.
Also, I have used an extra line and variable to read the value of visit code
before the second form is opened. As is in your code, the active form when
you get to that line is the second (already opened), so Me.[Visit Code] will
return a glorious null there!

HTH,
Nikos

[QUOTE="George Papadopoulos"]
Greetings everybody

I am building a database based on Microsoft Access. The database stores
'Technician report sheets info'. I have these two tables, the first stores
information about 'technician visit' such as technician code, serviced
company name, e.t.c. The second table stores various 'spare parts'[/QUOTE][/QUOTE] used[QUOTE]
in[/QUOTE] have[QUOTE]
a[QUOTE]
button on the first form (techician visit) such that when it is[/QUOTE] pressed,
the[QUOTE]
second form opens but the foreign key of the second table (spare parts)
takes the value of 'technician visit code' from the first form.
I have used the below code :

Private Sub Add_spare_Click()
On Error GoTo Err_cmdGoHere_Click
Dim stDocName As String

stDocName = "STOIXEIA_ANTALLAKTIKWN"
DoCmd.OpenForm stDocName

[Forms].stDocName.[Visit Code].SetFocus
[Forms].stDocName.[Visit Code].Code = Me.[Visit Code].Code

Exit_cmdGoHere_Click:
Exit Sub

Err_cmdGoHere_Click:
MsgBox Err.Description
Resume Exit_cmdGoHere_Click


End Sub

for the button event handler. When I press the button though, I get the
error 'Object doesn`t support the property or method'.

Am I missing something?
[/QUOTE]
[/QUOTE]
[/QUOTE]
 
Amy,

You could use a macro instead, with an action to open the next form, and one
to set the key value, something like:

Action: OpenForm
Arguments: FormName: Your form's name

Action: SetValue
Arguments: Item: Forms!SecondFormName!ControlName
Expression: Forms!FirstFormName!ControlName

changing the forms and controls names to the actual names in your design.

HTH,
Nikos
 
Back
Top