Moving input to different form

  • Thread starter bg-consult as, Leif Hauge
  • Start date
B

bg-consult as, Leif Hauge

Hi !
Need more help in my database, this time probably an easy task :

I input digits into a field called [Input] in one form. I have made a button
that open a different form with a filter where a field from the new form
called [PhoneNo] is similar to [Input] from the previous form. This works
well.

But, I want to add a special function, where the following happens :
- If the field [PhoneNo] is empty, the input from [Input] should be inserted
automatically, and if the field [PhoneNo] allready is filled out, it should
do nothing.

Could you please help me create the code for this ?

So far I have this :

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![Input] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Best regards
Leif Hauge
 
B

bg-consult as, Leif Hauge

No inputs ?
I guess I would have to store the value from [Input] to some kind of Session
or variable, and restore it in the other form, but don't know how to do
that. Please help !

Best regards
Leif Hauge
 
M

Marshall Barton

I input digits into a field called [Input] in one form. I have made a button
that open a different form with a filter where a field from the new form
called [PhoneNo] is similar to [Input] from the previous form. This works
well.

But, I want to add a special function, where the following happens :
- If the field [PhoneNo] is empty, the input from [Input] should be inserted
automatically, and if the field [PhoneNo] allready is filled out, it should
do nothing.

Could you please help me create the code for this ?

So far I have this :

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![Input] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Here's an idea. Use the OpenForm method's OpenArgs argument
to pass the input value to form1:

DoCmd.OpenForm stDocName, _
WhereCondition:= stLinkCriteria, _
OpenArgs:= Me![Input]

Then, you can use it in form1, possible(?) in the Load
event:

If IsNull(Me.PhoneNo) Then
Me.PhoneNo = Me.OpenArgs
End If
 
B

bg-consult as, Leif Hauge

Marshall Barton said:
I input digits into a field called [Input] in one form. I have made a button
that open a different form with a filter where a field from the new form
called [PhoneNo] is similar to [Input] from the previous form. This works
well.

But, I want to add a special function, where the following happens :
- If the field [PhoneNo] is empty, the input from [Input] should be inserted
automatically, and if the field [PhoneNo] allready is filled out, it should
do nothing.

Could you please help me create the code for this ?

So far I have this :

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![Input] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Here's an idea. Use the OpenForm method's OpenArgs argument
to pass the input value to form1:

DoCmd.OpenForm stDocName, _
WhereCondition:= stLinkCriteria, _
OpenArgs:= Me![Input]

Then, you can use it in form1, possible(?) in the Load
event:

If IsNull(Me.PhoneNo) Then
Me.PhoneNo = Me.OpenArgs
End If

Thx for your reply. The first part seems to work ok, to input the OpenArgs
as you said. I do not get error message, but do not know how to verify if
the Input was saved to OpenArgs.

But, the second part is not working. Where do you suggest I add this code ?
I tried to add it into the "Before update" for the PhoneNo field, but
nothing happens when the form is loaded. I set Me.PhoneNo to the value from
OpenArgs, but will this set the field value also ?

Best regards
Leif Hauge
 
M

Marshall Barton

"Marshall Barton" skrev
I input digits into a field called [Input] in one form. I have made a button
that open a different form with a filter where a field from the new form
called [PhoneNo] is similar to [Input] from the previous form. This works
well.

But, I want to add a special function, where the following happens :
- If the field [PhoneNo] is empty, the input from [Input] should be inserted
automatically, and if the field [PhoneNo] allready is filled out, it should
do nothing.

Could you please help me create the code for this ?

So far I have this :

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![Input] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Here's an idea. Use the OpenForm method's OpenArgs argument
to pass the input value to form1:

DoCmd.OpenForm stDocName, _
WhereCondition:= stLinkCriteria, _
OpenArgs:= Me![Input]

Then, you can use it in form1, possible(?) in the Load
event:

If IsNull(Me.PhoneNo) Then
Me.PhoneNo = Me.OpenArgs
End If

Thx for your reply. The first part seems to work ok, to input the OpenArgs
as you said. I do not get error message, but do not know how to verify if
the Input was saved to OpenArgs.

But, the second part is not working. Where do you suggest I add this code ?
I tried to add it into the "Before update" for the PhoneNo field, but
nothing happens when the form is loaded. I set Me.PhoneNo to the value from
OpenArgs, but will this set the field value also ?


As long as the PhoneNo field is bound to a control, the code
should work (if it's used in the right place). Be careful
in your teminology usage. A "field" is a column in the
form's record source table/query. A control is an object on
the form that can be used to view/edit a value.

I don't know where/when you want to do it, but the control's
BeforeUpdate event is definitely not the right place. Maybe
you want the form's BeforeUpdate event, but I can't be sure
without more details about what situation you are trying to
deal with.
 
B

bg-consult as, Leif Hauge

Marshall Barton said:
I input digits into a field called [Input] in one form. I have made a button
that open a different form with a filter where a field from the new form
called [PhoneNo] is similar to [Input] from the previous form. This works
well.

But, I want to add a special function, where the following happens :
- If the field [PhoneNo] is empty, the input from [Input] should be inserted
automatically, and if the field [PhoneNo] allready is filled out, it should
do nothing.

Could you please help me create the code for this ?

So far I have this :

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![Input] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Here's an idea. Use the OpenForm method's OpenArgs argument
to pass the input value to form1:

DoCmd.OpenForm stDocName, _
WhereCondition:= stLinkCriteria, _
OpenArgs:= Me![Input]

Then, you can use it in form1, possible(?) in the Load
event:

If IsNull(Me.PhoneNo) Then
Me.PhoneNo = Me.OpenArgs
End If

Thx for your reply. The first part seems to work ok, to input the OpenArgs
as you said. I do not get error message, but do not know how to verify if
the Input was saved to OpenArgs.

But, the second part is not working. Where do you suggest I add this code ?
I tried to add it into the "Before update" for the PhoneNo field, but
nothing happens when the form is loaded. I set Me.PhoneNo to the value from
OpenArgs, but will this set the field value also ?
 
M

Marshall Barton

Thx for your reply. The first part seems to work ok, to input the OpenArgs
as you said. I do not get error message, but do not know how to verify if
the Input was saved to OpenArgs.

But, the second part is not working. Where do you suggest I add this code ?
I tried to add it into the "Before update" for the PhoneNo field, but
nothing happens when the form is loaded. I set Me.PhoneNo to the value from
OpenArgs, but will this set the field value also ?


It appears that you have missed my reply to your identical
followup four days ago. Just in that case that's what
happened, here it is again:
-------------------------------------------------------------------------
As long as the PhoneNo field is bound to a control, the code
should work (if it's used in the right place). Be careful
in your teminology usage. A "field" is a column in the
form's record source table/query. A control is an object on
the form that can be used to view/edit a value.

I don't know where/when you want to do it, but the control's
BeforeUpdate event is definitely not the right place. Maybe
you want the form's BeforeUpdate event, but I can't be sure
without more details about what situation you are trying to
deal with.
 
B

bg-consult as, Leif Hauge

Marshall Barton said:
It appears that you have missed my reply to your identical
followup four days ago. Just in that case that's what
happened, here it is again:
-------------------------------------------------------------------------
As long as the PhoneNo field is bound to a control, the code
should work (if it's used in the right place). Be careful
in your teminology usage. A "field" is a column in the
form's record source table/query. A control is an object on
the form that can be used to view/edit a value.

I don't know where/when you want to do it, but the control's
BeforeUpdate event is definitely not the right place. Maybe
you want the form's BeforeUpdate event, but I can't be sure
without more details about what situation you are trying to
deal with.

Thanks alot for your reply. You are right, I did not see your reply before
now.
Also sorry for using wrong terms for the various types of objects, I am no
expert on this, more like a amateur =)
The code would probably work, I think it is just I don't enter it in the
right places.

The INPUT is a _control_ in the first form page. I edited the "event
procedure" vb code for one "search" button to run the code :

stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![INPUT] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, OpenArgs:=Me![INPUT]

Then my problem is (if this so far is correct) :
Where do I edit the Form1 to add the second part of your solution (see
below) ? How do I edit the load event for Form1 ?

If IsNull(Me.PhoneNo) Then
Me.PhoneNo = Me.OpenArgs
End If

Best regards
Leif Hauge
 
M

Marshall Barton

Marshall Barton said:
It appears that you have missed my reply to your identical
followup four days ago. Just in that case that's what
happened, here it is again:
-------------------------------------------------------------------------
As long as the PhoneNo field is bound to a control, the code
should work (if it's used in the right place). Be careful
in your teminology usage. A "field" is a column in the
form's record source table/query. A control is an object on
the form that can be used to view/edit a value.

I don't know where/when you want to do it, but the control's
BeforeUpdate event is definitely not the right place. Maybe
you want the form's BeforeUpdate event, but I can't be sure
without more details about what situation you are trying to
deal with.

Thanks alot for your reply. You are right, I did not see your reply before
now.
Also sorry for using wrong terms for the various types of objects, I am no
expert on this, more like a amateur =)
The code would probably work, I think it is just I don't enter it in the
right places.

The INPUT is a _control_ in the first form page. I edited the "event
procedure" vb code for one "search" button to run the code :

stDocName = "Form1"
stLinkCriteria = "[PhoneNo]=" & "'" & Me![INPUT] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, OpenArgs:=Me![INPUT]

Then my problem is (if this so far is correct) :
Where do I edit the Form1 to add the second part of your solution (see
below) ? How do I edit the load event for Form1 ?

If IsNull(Me.PhoneNo) Then
Me.PhoneNo = Me.OpenArgs
End If
The load event would only be appropriate if Form1 will only
have one existing record or no records.

If you want that phone number for all new records in Form1
(until it is closed), then the form's BeforeUpdate event
would be a good place.

I would need to know more about how Form1 is used before I
could be more specific.

You can create and/or locate any event procedure by first
locating the appropriate event **property** in the form's
property sheet. After you click somewhere on the line for
the property, a little button with three dots will appear in
the right margin. Click on the little button (and if
prompted select Event procedure). This will open the Visual
Basic Editor and put the cursor in the procedure.
 

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