ralphus
You have a lot of talent trying to help you on this post.
(Congrats
AceMan on TipMaster of the Week -- Awesome!)
We know what you are trying to do - can be done.
I suspect the problem is that those trying to provide support are lacking specific details.
To achieve the objective, you need to...
- open the form
- provide a valid link criteria
- a valid criteria is
-- a) found on the current / source form as control field variable, for example, a text box,
-- b) is also used on the target form
-- c) the data types have to match on the source and target. If you use a long numeric integer on the source, the target field uses the same
-- d) the syntax has to be correct. Text strings have to encaspulated with " quotes, date fields have to be encapsulated with # octophorps.
A typical example of coding is...
Code:
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmEmployeeMaster
stLinkCriteria = "[EmpID]=" & Me.EmpID
DoCmd.OpenForm stDocName, , , stLinkCriteria
Now looking at your code with comments in green...
Code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim stFormName As String[COLOR=green]
'Why are you using stFormName in addition to stDocName?
[/color]
stDocName = "Product_Table"[COLOR=green]
'Unusual to have a form named Product_Table except
'Access will default to the name of the table when
'creating a form using the wizard -- in future
'consider changing the name to something like [b]frmProduct[/b]
[/color]
stFormName = "Site_Table"[COLOR=green]
'Man am I puzzled what your are trying to do.
[/color]
stLinkCriteria = "[Site_Name]=" & Me![Site_Name] [COLOR=green]
'This looks problematic.
'1) [Site_Name] is most likely a text string which means
' that you need to encapsulated the text string within quotes
'2) Me![Site_Name] is valid, but if you use Me.Site_Name
' Access will allow you to pick the variable name from a
' pick list
[/color]
DoCmd.OpenForm stDocName, , , stLinkCriteria [COLOR=green]
'This looks fine
'Since you open the form with a "new record",
'- stDocName is correct
'- stLinkCriteria is not correct[/color]
DoCmd.Close acForm, stFormName, acSaveNo [COLOR=green]
'What is the prupose of this?
'Are you closing one form after loading the other?[/color]
I think the following will work for you with comments prefaced with a single quote ' ...
Code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim strQ as String
strQ = Chr$(34) 'quote character, my way
stDocName = "Product_Table"
' Get site name from form and encapsulate with quotes
stLinkCriteria = "[Site_Name]=" & strQ & Me.Site_Name & strQ
' Open target form with link criteria
DoCmd.OpenForm stDocName, , , stLinkCriteria
' Close current form using Me.Name reference
DoCmd.Close acForm, Me.Name, acSaveNo
Richard