473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

copying data between forms on DoCmd.OpenForm

Here's what I've got:

I've got a form with combo boxes. you can select already existing
company names or type in new ones. if you type in a new one, it
prompts you to double click the combo box if you want to add a new
company. when you double click it brings up the new company form so
you can enter the rest of the information besides just the name there.
This all works.

Here's what I want:

I want the new company that is typed in the first form (and causes the
double click prompt) to be copied into the new company form, so the
name doesn't have to be typed twice.

Form information:

First form is called 'Quote'
Combo Box I'm using is 'CompanyID'

Second form is 'Company'
Text Box that i want the info to go to is 'CompanyNickname'

I've tried using the Wherecondition in the docmd.openform but it
doesn't work.

Thanks in advance for the help and for posting the reply to the groups.

Here's the code:

Private Sub CompanyID_NotInList(NewData As String, Response As Integer)
MsgBox "Double-click this field to add an entry to the list."
Response = acDataErrContinue
End Sub
Private Sub CompanyID_DblClick(Cancel As Integer)
On Error GoTo Err_CompanyID_DblClick
Dim lngCompanyID As Long

If IsNull(Me![CompanyID]) Then
Me![CompanyID].Text = ""
Else
lngCompanyID = Me![CompanyID]
Me![CompanyID] = Null
End If
DoCmd.OpenForm "Company", , , "[CompanyNickname] = ' & Me!CompanyID
& '", , acDialog, "GotoNew"
Me![CompanyID].Requery
If lngCompanyID <> 0 Then Me![CompanyID] = lngCompanyID

Exit_CompanyID_DblClick:
Exit Sub

Err_CompanyID_DblClick:
MsgBox Err.Description
Resume Exit_CompanyID_DblClick
End Sub

Nov 13 '05 #1
6 4173
Use OpenArgs on the Load event of your Company form:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me![CompanyNameField] = Me.OpenArgs
Forms![Company]![Address].SetFocus
End If
End Sub

I also fire the OpenForm directly from the combo box on the On Not In
List event when the item typed does not match anything in the list:

Private Sub CoID_NotInList(NewData As String, Response As Integer)
Dim result
Dim msg As String
Dim cr As String
cr = Chr$(13)
If NewData = "" Then Exit Sub
msg = "'" & NewData & "' is not in the list." & cr & cr
msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
DoCmd.OpenForm "Company", , , , acAdd, acDialog, NewData
End If
result = DLookup("[CompanyNameField]", "Company", "[CompanyNameField]=
" & Chr(34) & NewData & Chr(34))
If IsNull(result) Then
Response = acDataErrContinue
MsgBox "Please try again!"
Else
Response = acDataErrAdded
End If
End Sub

Supply your own field and form names. Good luck!!

Nov 13 '05 #2
Thanks so much. i thought i replied yesterday, but apparently i'm
don't know how to use google groups correctly. It works beautifully
and i quit using my old code entirely. i trimmed out several things.
i didn't know what the result= line was for, so i took it out, and i
took out everything below that because it was causing 'text is not in
the list' errors to come up even though it was going into the creation.
here's what i have left. Thanks again.
Quote Form:

Private Sub CompanyID_NotInList(NewData As String, Response As Integer)
Dim result
Dim msg As String
Dim cr As String
cr = Chr$(13)
If NewData = "" Then Exit Sub

msg = "'" & NewData & "' is not in the list." & cr & cr

msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
DoCmd.OpenForm "Company", , , , acAdd, acDialog, NewData
End If

End Sub
----
Company Form:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then

Me![CompanyNickname] = Me.OpenArgs

Forms![quote]![CompanyID].SetFocus

End If
End Sub
------
Koontzie wrote:
Use OpenArgs on the Load event of your Company form:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me![CompanyNameField] = Me.OpenArgs
Forms![Company]![Address].SetFocus
End If
End Sub

I also fire the OpenForm directly from the combo box on the On Not In
List event when the item typed does not match anything in the list:

Private Sub CoID_NotInList(NewData As String, Response As Integer)
Dim result
Dim msg As String
Dim cr As String
cr = Chr$(13)
If NewData = "" Then Exit Sub
msg = "'" & NewData & "' is not in the list." & cr & cr
msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
DoCmd.OpenForm "Company", , , , acAdd, acDialog, NewData
End If
result = DLookup("[CompanyNameField]", "Company", "[CompanyNameField]= " & Chr(34) & NewData & Chr(34))
If IsNull(result) Then
Response = acDataErrContinue
MsgBox "Please try again!"
Else
Response = acDataErrAdded
End If
End Sub

Supply your own field and form names. Good luck!!


Nov 13 '05 #3
problem. i have the data entry form and then i have a data edit form.
i get an error when i apply the same script to the data edit form.

Is there a way to change the code below so it knows what form it's
coming from and then run the appropriate line? Either
Forms![quote]![CompanyID].SetFocus or Forms![Quote
Edit]![CompanyID].SetFocus

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then

Me![CompanyNickname] = Me.OpenArgs

Forms![quote]![CompanyID].SetFocus

End If
End Sub

Thanks.

beowulfs wrote:
Thanks so much. i thought i replied yesterday, but apparently i'm
don't know how to use google groups correctly. It works beautifully
and i quit using my old code entirely. i trimmed out several things.
i didn't know what the result= line was for, so i took it out, and i
took out everything below that because it was causing 'text is not in
the list' errors to come up even though it was going into the creation. here's what i have left. Thanks again.
Quote Form:

Private Sub CompanyID_NotInList(NewData As String, Response As Integer) Dim result
Dim msg As String
Dim cr As String
cr = Chr$(13)
If NewData = "" Then Exit Sub

msg = "'" & NewData & "' is not in the list." & cr & cr

msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
DoCmd.OpenForm "Company", , , , acAdd, acDialog, NewData
End If

End Sub
----
Company Form:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then

Me![CompanyNickname] = Me.OpenArgs

Forms![quote]![CompanyID].SetFocus

End If
End Sub
------
Koontzie wrote:
Use OpenArgs on the Load event of your Company form:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me![CompanyNameField] = Me.OpenArgs
Forms![Company]![Address].SetFocus
End If
End Sub

I also fire the OpenForm directly from the combo box on the On Not In List event when the item typed does not match anything in the list:

Private Sub CoID_NotInList(NewData As String, Response As Integer)
Dim result
Dim msg As String
Dim cr As String
cr = Chr$(13)
If NewData = "" Then Exit Sub
msg = "'" & NewData & "' is not in the list." & cr & cr
msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
DoCmd.OpenForm "Company", , , , acAdd, acDialog, NewData
End If
result = DLookup("[CompanyNameField]", "Company",

"[CompanyNameField]=
" & Chr(34) & NewData & Chr(34))
If IsNull(result) Then
Response = acDataErrContinue
MsgBox "Please try again!"
Else
Response = acDataErrAdded
End If
End Sub

Supply your own field and form names. Good luck!!


Nov 13 '05 #4
Private Sub Form_Load()
If IsNull(Me.OpenArgs) Then
Forms("Quote Edit").CompanyID.SetFocus
Else
Me.CompanyNickname = Me.OpenArgs
Forms("Quote").CompanyID.SetFocus
End If
End Sub
Darryl Kerkeslager
"beowulfs" <tr**@scheh.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
problem. i have the data entry form and then i have a data edit form.
i get an error when i apply the same script to the data edit form.

Is there a way to change the code below so it knows what form it's
coming from and then run the appropriate line? Either
Forms![quote]![CompanyID].SetFocus or Forms![Quote
Edit]![CompanyID].SetFocus

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then

Me![CompanyNickname] = Me.OpenArgs

Forms![quote]![CompanyID].SetFocus

End If
End Sub

Thanks.

Nov 13 '05 #5
Thanks for the code, but it doesn't work. it runs through first one
always. i need something that will determine which form is the
referrer. so like,
if form referrer is "Quote" then ' <-------don't know how to do this
If IsNull(Me.OpenArgs) Then
Forms("Quote").CompanyID.SetFocus
End If
Else If Form referrer is "Quote Edit" Then '<-------don't know how
to do this
If IsNull(Me.OpenArgs)Then
Forms("Quote Edit").CompanyID.SetFocus
End If
End If
Else
End If

I just don't know how to call up a form referrer property, if there
even is such a thing. Thanks again.

Darryl Kerkeslager wrote:
Private Sub Form_Load()
If IsNull(Me.OpenArgs) Then
Forms("Quote Edit").CompanyID.SetFocus
Else
Me.CompanyNickname = Me.OpenArgs
Forms("Quote").CompanyID.SetFocus
End If
End Sub
Darryl Kerkeslager
"beowulfs" <tr**@scheh.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
problem. i have the data entry form and then i have a data edit form. i get an error when i apply the same script to the data edit form.

Is there a way to change the code below so it knows what form it's
coming from and then run the appropriate line? Either
Forms![quote]![CompanyID].SetFocus or Forms![Quote
Edit]![CompanyID].SetFocus

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then

Me![CompanyNickname] = Me.OpenArgs

Forms![quote]![CompanyID].SetFocus

End If
End Sub

Thanks.


Nov 13 '05 #6
What my code assumed was that when you were opening the Form from Form
"QuoteEdit", that you would not use any OpenArgs, thus it would be Null
and this line would run:
Forms("Quote Edit").CompanyID.SetFocus
Perhaps you need to test for Len(Me.OpenArgs)=0 instead of IsNull, but the
principle is the same.
Darryl Kerkeslager

"beowulfs" <tr**@scheh.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Thanks for the code, but it doesn't work. it runs through first one
always. i need something that will determine which form is the
referrer. so like,
if form referrer is "Quote" then ' <-------don't know how to do this
If IsNull(Me.OpenArgs) Then
Forms("Quote").CompanyID.SetFocus
End If
Else If Form referrer is "Quote Edit" Then '<-------don't know how
to do this
If IsNull(Me.OpenArgs)Then
Forms("Quote Edit").CompanyID.SetFocus
End If
End If
Else
End If

I just don't know how to call up a form referrer property, if there
even is such a thing. Thanks again.

Darryl Kerkeslager wrote:
Private Sub Form_Load()
If IsNull(Me.OpenArgs) Then
Forms("Quote Edit").CompanyID.SetFocus
Else
Me.CompanyNickname = Me.OpenArgs
Forms("Quote").CompanyID.SetFocus
End If
End Sub
Darryl Kerkeslager
"beowulfs" <tr**@scheh.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
problem. i have the data entry form and then i have a data edit

form. i get an error when i apply the same script to the data edit form.

Is there a way to change the code below so it knows what form it's
coming from and then run the appropriate line? Either
Forms![quote]![CompanyID].SetFocus or Forms![Quote
Edit]![CompanyID].SetFocus

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then

Me![CompanyNickname] = Me.OpenArgs

Forms![quote]![CompanyID].SetFocus

End If
End Sub

Thanks.

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Scott | last post by:
Creating an application in Access with a number of "screens" which are just forms linked together by command buttons (click button, opens new form, closes old form). Each form opens and...
1
by: Doug | last post by:
I have a Do-Loop routine that checks the values of certain fields in a Form (F_OmissionCheck) for omissions. If the field is blank, the strOmissions variable is modified with additional verbiage...
7
by: aaaaaa | last post by:
Hi, I created some forms and during the wizard I chose the Datasheet View, and when I open the forms from the main objects window they open up in datasheet view. But when I created a switchboard...
1
by: David B | last post by:
I have an app which handles data relating to cattle. The ear tag number consists of 3 parts. Country code - UK. Farm Code - 107248. and animal number - 600555. At present the complete set has...
2
by: nic | last post by:
Hi I am currently having problems getting two forms to behave the way I want. I have two tables Student and Application, and their respective forms. (Tables)Student has StudentID (PK) & an...
0
by: jpr | last post by:
Hello, I need some help. I have a form named MASTER based on a table also called MASTER. A control of my form in names SSN which stores the client SSN. On the same form I have placed a subform...
4
by: Parasyke | last post by:
I have what is probably a simple fix for the gurus. I have one form that has several products listed and I want to double-click onto the field to bring up a more detailed product form of the chosen...
4
D Giles
by: D Giles | last post by:
Have found many solutions on this forum to get to this point so finally registered. I have a form which should load 17 forms. Private Sub Form_Load() On Error GoTo Err_Form_Load DoCmd.Minimize...
2
seraieis
by: seraieis | last post by:
Hi all, I have an Access database with roughtly 70 different forms that I need to change the background image for. Now, short of opening all these forms individually, and changing the "Picture"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.