From code does not work

Archie999

Access Wannabee
Local time
Today, 02:43
Joined
May 25, 2003
Messages
45
Hi,

I was hoping someone could explain why the following code does not work. Hopefully it is enough to go on.

I would like a form, on opening, to run some code if there is an OpenArg value. In the code below me.MyIssueID is the OpenArg. I am trying to populate an unbound control with table values. If you need more, just let me know but perhaps it is something dead obvious. Thanks in advance.

PS. You can see I've added some msgbox for troubleshooting. I see the first one (IssueIDx) but NONE of the others. Seems we are not even getting that far.

Private Sub Form_Activate()

Dim IssueIDx As Integer
Dim ProductIDx As Integer
Dim ProductNamex As String

IssueIDx = Me.MyIssueID
MsgBox IssueIDx

If len(IssueIDx) > 0 Then

ProductIDx = DLookup("[ProductID]", "tblIssue", "[MyIssueID = IssueIDx]")
MsgBox ProductIDx

ProductNamex = DLookup("[ProductName]", "tblProduct", "[MyProductID = ProductIDX]")
Me.ProductID = ProductNamex
MsgBox ProductNamex

Else
Me.MyIssueID.Requery
MsgBox "Else"
End If

End Sub
 
Try this to test for OpenArgs.

Code:
If Me.OpenArgs Then
   'code that runs if openargs passed to form
End If

Or simply replace this line...
Code:
IssueIDx = Me.MyIssueID

with this:
Code:
IssueIDx = Me.OpenArgs

Regards,
Tim
 
Works Now

Thanks Tim, I used your suggestion, it is much simpler.

However, it still did not work. I found another error (in the Dlookup) and got it working so I am just posting the code that worked in case anyone has a similar issue some time.


Private Sub Form_Activate()

Dim IssueIDx As Integer
Dim ProductIDx As Integer
Dim ProductNamex As String

IssueIDx = Me.OpenArgs

If Me.OpenArgs Then

ProductIDx = DLookup("[ProductID]", "tblIssue", "[MyIssueID]=" & IssueIDx)
ProductNamex = DLookup("[ProductName]", "tblProduct", "[MyProductID]=" _
& ProductIDx)
Me.ProductID = ProductNamex

Else
Me.MyIssueID.Requery

End If
 
Archie,

Glad to hear it.

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom