Open New Form with Criteria

gobogirl

Registered User.
Local time
Tomorrow, 04:20
Joined
Jul 28, 2004
Messages
10
Hi. I'm a newbie. I'm stuck and would really appreciate your help. I have searched Google, this forum and others. I have found codes and tips for similar problems and have tried applying many of them but to no avail (?!). Here's the rundown.

I am on Access 2000 on XP -
Form 1: frmCompany (incl subfrmAddress, lstContacts and other info)
Form 2: frmContacts (incl cboCompanyID and other info)

cboCompanyID rowsource data is:
SELECT [tblCompany].[CompanyID], [tblCompany].[CoName], [tblAddress].[AddressID], [tblAddress].[CityTown], [tblAddress].[Country], [tblCompany].[DialPrefix] FROM tblCompany INNER JOIN tblAddress ON [tblCompany].[CompanyID]=[tblAddress].[CompanyID];

Note that only [tblCompany].[CoName] , [tblAddress].[CityTown], [tblAddress].[Country] is displayed in the combobox. This is because many of the companies have offices in various locations around the world. Each office location is treated as a different and separate company although they have the same name.


WHAT I'M TRYING TO ACHIEVE
From the frmCompany click a button to open a blank frmContacts and automatically select and fill cboCompany.
The frmContacts opens, but does not populate cboCompanyID (I am expecting the number of Company records to be around a thousand thus prefer to open frmContacts from frmCompany and auto-fill the cboCompanyID).

Here is where i'm up to now... and it doesn't work!:

Private Sub AddNewPerson_Click()
On Error GoTo Err_AddNewPerson_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmContacts"

stLinkCriteria = "[cboCompanyID] =" & Me.txtCompanyID
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd

Exit_AddNewPerson_Click:
Exit Sub

Err_AddNewPerson_Click:
MsgBox Err.Description
Resume Exit_AddNewPerson_Click

End Sub

Can anyone please help?
 
If i understand your question correctly you are looking for the OpenArgs feature. Search this forum for OpenArgs, there are several examples on how to do this !
 
Thank you Maxmangion. I'm on my way to search. :o
 
Please help.

I've changed tact to OpenArgs on Maxmangion's suggestion (btw - thanx). But I still can't make it work! :(
Please can anyone tell me what i'm doing wrong and how I can fix this.

'on my frmCompany -

Private Sub cmdAddNewPerson_Click()
On Error GoTo Err_cmdAddNewPerson_Click

Dim stDocName As String

stDocName = "frmContacts"

DoCmd.OpenForm stDocName, , , , acFormAdd, , Me.txtCompanyID

Exit_cmdAddNewPerson_Click:
Exit Sub

Err_cmdAddNewPerson_Click:
MsgBox Err.Description
Resume Exit_cmdAddNewPerson_Click

End Sub


'And on my frmContacts -
Private Sub Form_BeforeInsert(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.cboCompanyID.Column(1) = OpenArgs
End Sub

Thanks in advance.
Pat.
 
Last edited:
'And on my frmContacts -
Private Sub Form_BeforeInsert(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.cboCompanyID.Column(1) = OpenArgs
End Sub

I do the following (however, not sure if it is the right approach)

Private Sub Form_Load()
If Me.OpenArgs <> "" Then
Me.FieldName = Me.OpenArgs
End If
End Sub

Note that i use the onLoad event rather than before insert, and don't forget to replace fieldname with the name of your control.
 
Thank you, Maxmangion! You're a star! :p
It worked! :D
When you have a moment, can you explain the arguement so that i can understand rather than simply copy/paste.

Cheers, Pat.
 

Users who are viewing this thread

Back
Top Bottom