Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening form from dbl click blank if no data in control

Status
Not open for further replies.

dragongunner0351

Programmer
Mar 16, 2006
104
US
Hello all, I have an event that executes when the user double clicks a partNumber Control:

code:
DoCmd.OpenForm "Product Details", , , "[Products]![ID] = " & Me![Product ID]

This opens a details form for that partNumber. Is it possible for it to open a blank Product Details form if there is no partNumber in the parNumber control?

The end result I'm looking for is,
1. if there is a partNumber in the partNumber control then open the Product Details form to show the details on that partNumber.
2. if there is no partNumber, then open the Products Details form blank so that it can be added to the inventory list.
 
I think this is what your wanting not a lot of code to look at but here goes:

If Me![Product ID]="" Then

DoCmd.OpenForm "Product Details"
Else
DoCmd.OpenForm "Product Details", , , "[Products]![ID] = " & Me![Product ID]

End If
 
I'd be careful about using "" in Access, try using IsNull instead or converting the Null value with Nz.
 
dragongunner0351 . . .

. . . or perhaps the following:
Code:
[blue]   Dim Cri As String
   
   If Trim(Me![Product ID] & "") = "" Then
      DoCmd.OpenForm "Product Details", , , , acFormAdd
   Else
      Cri = "[Products]![ID] = " & Me![Product ID]
      DoCmd.OpenForm "Product Details", , , Cri
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top