New record from prev. form

ailyn

Registered User.
Local time
Today, 06:26
Joined
Sep 16, 2005
Messages
31
I have a tbl Orders and its form Orders from where I open/make Proformas (tbl Proformas, form Proformas) in tbl Proformas I have OrderId that comes from tbl Orders, of course.
Now when I try to open/make a proforma with this:

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Proformas"
stLinkCriteria = "[Proformas_OrderId] = " & Me![OrderId]
If IsNull(stLinkCriteria) Then
DoCmd.OpenForm stDocName, , , , acFormAdd
Forms!Proformas.Form!ProformasOrderIdctrl = Me.OrderId
MsgBox "unexistant value"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly
MsgBox "exists"
End If

It always tries to open an existant record although and I get an empty form Proformas with the msgBox 'exists'. Why isn't it getting if the stLinkCriteria exists? Should I filter it otherwise?
 
Hey Ailyn,

Try:
If Trim(Nz(stLinkCriteria,"")) = "" Then
to check for Null or Empty stLinkCriteria and see if it will work. Obviously, it's not seeing stLinkCriteria with IsNull(stLinkCriteria) so let's see if it will work this way.

HTH,
Shane
 
Thanks Shane, but it still does the same. although this time it shows another record and the msgBox 'exists'.
Could it be that the stLinkCriteria is not good:
stLinkCriteria = "[Proformas_OrderId] = " & Me![OrderId]
As I said before I need to see if the OrderId is already in the Proformas table or otherwise I'll have to make a new proforma with the current OrderId
 
Ok, I found it:
If DCount("*", "Proformas", "OrderId=" & Me![OrderId]) > 0 Then
the problem is that strings cannot be null.
 
Hey Ailyn,

Where is "Proformas" being opened from? I'm assuming this code is behind a command button on a form since your checking "[Proformas_OrderId]" against "OrderId". Have you looked at "Proformas_OrderId" before clicking the command button and see if it has any data in it? The code string I gave you will check to see if stLinkCriteria is either Null or Empty, since it skipped adding a New Record then I think you need to evaluate why stLinkCriteria is not Null or Empty, like you want it to be, in order to add a new record.

I have to run to an appointment so hopefully someone else can jump in to help if you have further questions or problems.

Hope I've helped some,
Shane
 
Glad you found it and got it going.

Have a good day,
Shane
 

Users who are viewing this thread

Back
Top Bottom