automatic copy of data from one form when opening another

W

weircolin

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
K

Klatuu

I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If
 
W

weircolin

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?
 
K

Klatuu

Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.
 
W

weircolin

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks
 
K

Klatuu

If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If
 
W

weircolin

Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin said:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks
 
W

weircolin

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin said:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
K

Klatuu

The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin said:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
W

weircolin

Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin said:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
W

weircolin

Oops!

Got a problem now. The Question"...Do you want to create one?" comes
up now even if there is information for that person in the other table.

This is my code

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number]" = Me.[Reference Number])) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
DoCmd.close
End If
End If
End If
End If
End Sub

Any suggestions?

Thanks

Colin
Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin said:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
[email protected] wrote:
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
W

weircolin

Oh dear, noticed another one.

Whenever I open the form on its own I am getting the message popping up
too!

Think I'm gonna quit and take up knitting!

Colin
Oops!

Got a problem now. The Question"...Do you want to create one?" comes
up now even if there is information for that person in the other table.

This is my code

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number]" = Me.[Reference Number])) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
DoCmd.close
End If
End If
End If
End If
End Sub

Any suggestions?

Thanks

Colin
Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin said:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

:

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
[email protected] wrote:
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
W

weircolin

Sorry, sorted out the first problem, added an "Else in to the middle of
the code. Can't get to the bottom of last question I had.

Colin
Oh dear, noticed another one.

Whenever I open the form on its own I am getting the message popping up
too!

Think I'm gonna quit and take up knitting!

Colin
Oops!

Got a problem now. The Question"...Do you want to create one?" comes
up now even if there is information for that person in the other table.

This is my code

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number]" = Me.[Reference Number])) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
DoCmd.close
End If
End If
End If
End If
End Sub

Any suggestions?

Thanks

Colin
Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin
Klatuu wrote:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

:

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
[email protected] wrote:
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
W

weircolin

Ok, the Else is causing the problem. Don't know how else to get it to
work without it though.

Thanks

Colin
Sorry, sorted out the first problem, added an "Else in to the middle of
the code. Can't get to the bottom of last question I had.

Colin
Oh dear, noticed another one.

Whenever I open the form on its own I am getting the message popping up
too!

Think I'm gonna quit and take up knitting!

Colin
Oops!

Got a problem now. The Question"...Do you want to create one?" comes
up now even if there is information for that person in the other table.

This is my code

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number]" = Me.[Reference Number])) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
DoCmd.close
End If
End If
End If
End If
End Sub

Any suggestions?

Thanks

Colin
[email protected] wrote:
Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin
Klatuu wrote:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

:

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
[email protected] wrote:
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
K

Klatuu

As to opening the form on it's own, that is easily corrected by testing to
see if the first form is loaded and coding for that circumstance.

If Application.CurrentProject.AllForms("MyForm").IsLoaded Then
' The form is loaded
Else
' The form is not loaded.
End If

I guess I don't understand the part about the person being in the other
tables or the problem with the Else statement. Maybe you could post back
with the code as it is now and some more detail on your problem.


Ok, the Else is causing the problem. Don't know how else to get it to
work without it though.

Thanks

Colin
Sorry, sorted out the first problem, added an "Else in to the middle of
the code. Can't get to the bottom of last question I had.

Colin
Oh dear, noticed another one.

Whenever I open the form on its own I am getting the message popping up
too!

Think I'm gonna quit and take up knitting!

Colin
[email protected] wrote:
Oops!

Got a problem now. The Question"...Do you want to create one?" comes
up now even if there is information for that person in the other table.

This is my code

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number]" = Me.[Reference Number])) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
DoCmd.close
End If
End If
End If
End If
End Sub

Any suggestions?

Thanks

Colin
[email protected] wrote:
Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin
Klatuu wrote:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

:

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
[email protected] wrote:
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
W

weircolin

Hi

I had been making a silly error with the code but it is working great
now!

Thank you for all your help. Much appreciated!

Colin said:
As to opening the form on it's own, that is easily corrected by testing to
see if the first form is loaded and coding for that circumstance.

If Application.CurrentProject.AllForms("MyForm").IsLoaded Then
' The form is loaded
Else
' The form is not loaded.
End If

I guess I don't understand the part about the person being in the other
tables or the problem with the Else statement. Maybe you could post back
with the code as it is now and some more detail on your problem.


Ok, the Else is causing the problem. Don't know how else to get it to
work without it though.

Thanks

Colin
Sorry, sorted out the first problem, added an "Else in to the middle of
the code. Can't get to the bottom of last question I had.

Colin
[email protected] wrote:
Oh dear, noticed another one.

Whenever I open the form on its own I am getting the message popping up
too!

Think I'm gonna quit and take up knitting!

Colin
[email protected] wrote:
Oops!

Got a problem now. The Question"...Do you want to create one?" comes
up now even if there is information for that person in the other table.

This is my code

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number]" = Me.[Reference Number])) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
DoCmd.close
End If
End If
End If
End If
End Sub

Any suggestions?

Thanks

Colin
[email protected] wrote:
Hi there

Magic - worked a treat! Thank you! Much appreciated!

Colin
Klatuu wrote:
The reference to the control has to be outside the quotes:
Instead of this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Do this:
If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = " & Me.[Reference Number])) Then

As to your previous question, you will probably need to add this:

If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
If Me.Dirty Then
Me.Undo
End If

:

Hi

Thanks for that code. I have used it with the reference number field
and I had to change it to allow it to work for an integer


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.[Reference Number] = varValues(0)
Me.[Surname] = varValues(1)
Me.[First Name] = varValues(2)
Me.Town = varValues(3)

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then
If MsgBox("No current Issue for this Person, would you like
to create one?", vbQuestion + vbYesNo) = vbNo Then
DoCmd.close
End If
End If
End If
End Sub

When I run it I am getting an error message:

Run-time error '2001'

You cancelled the previous opperation.

When I debug it the following line is highlighted.

If IsNull(DLookup("[Reference Number]", "tblissuesandconcerns",
"[Reference Number] = Me.[Reference Number]")) Then

Any suggestions?

Thanks again

Colin
[email protected] wrote:
Hi

Thanks for that, the error message is working fine. Problem I am
having is that if I click "No" it is still creating a record in the
table. Any ideas why?

Colin
Klatuu wrote:
If I am understanding correctly, you might try add this to your code (Note,
it is completely untested.

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
If IsNull(DLookup("[Name]", "YourTable", "[Name] = '" & Me.txtName &
"'") Then
If msgBox("No current Issue for this person, would you like to
create one?", vbQuestion + vbYesNo) = vbNo Then
Docmd.Close
End If
End If


:

Magic! Some guy!! Works great!

Only slight problem I have now is that if I want to see if that person
has an entry on the second form I click that button. It is fine if the
person already has information on it, but if they don't and I don't
want to put info on for them it automatically saves the information.
Is there anyway I could create a message to pop up to say something
like:

No current Issue for this person, would you like to create one?

Then have a yes or no option?

Thanks

Colin
Klatuu wrote:
Open the form in design viewl.
Select the properties dialog and select Form in the drop down.
Select the events tab.

:

Hi

Thanks for your reply. Excuse my ignorance, where would I find the
Load Event on the second form?

Colin
Klatuu wrote:
I would suggest using the OpenArgs argument of the OpenForm method and
setting the control values on the second form in the Load event. That way,
you dn't have to test to see if the first form is open. That also means that
the second form can be opened independantly from the first form. In that the
OperArgs is one string value, you can concatenate multiple values into one
string and parce the values in the second form. Hopefully, you are on at
least AC2K because the example I will show uses the Split function to
separate the values.

To open the second form:

strPassValues = Me.txtName & "~" & Me.txtRefNo
Docmd.OpenForm "SecondForm", , , , , , strPassValues

In the Load event of the second form:

Dim varValues as Variant

If Not IsNull(Me.OpenArgs) Then
varValues = Split(Me.OpenArgs, "~")
Me.txtName = varValues(0)
Me.txtRefNo = varValues(1)
End If


:

Hi

Is it possible when opening a form from a button in another form to
copy information automatically? Such as Name, Reference Number?

Thanks

Colin
 
Top