help with code on event call

J

jon

Hi

I am unsure how to code the following
the table I am working on is Baan
I am selecting the record using the orderNo field
but depending if the field IcyDate empty or not I will open different forms

the code I have in the event call at the moment is below and where I have
put the ***** is where I need an if statement to see if the field IcyDate is
empty or not


Private Sub But_SelONo_Click()
On Error GoTo Err_But_SelONo_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim intcount As Integer




intcount = DLookup("[Count-O-N]", "[Qu-cmm-countorders2]") ' the query
this refers to counts the number of orders there are against this order no


If intcount = 0 Then
MsgBox "Not a valid order No: or no order No entered." & " Please re
enter." 'If there are none it displays a message box
ElseIf intcount = 1 Then

*****
stDocName = "CmmBaanEntry"
stLinkCriteria = "[OrderNo]=" & Me![Txt_reqONo]
DoCmd.OpenForm stDocName, , , stLinkCriteria

If dateIcyBaan = VBA.date() Then
End If

DoCmd.Close acForm, "fr-cmm-select-order" ' if there is one
it will open the baan form with the oder loaded

ElseIf intcount > 1 Then ' if there is more
than 1 oder it opens a list of oders so the correct order can be selected
stDocName = "Frm-cmm-Select-stage"
stLinkCriteria = "[OrderNo]=" & Me![Txt_reqONo]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "fr-cmm-select-order"

End If







Exit_But_SelONo_Click:
Exit Sub

Err_But_SelONo_Click:
MsgBox Err.Description
Resume Exit_But_SelONo_Click

End Sub


Thanks

Jon
 
A

Arvin Meyer [MVP]

What doesn't work?

From what I can see, the only thing immediately obvious is that you don't
tell the DLookup code what [Order No] to count on., But that may read it
from the form when it is opened.
 
J

jon

Sorry I need a new if statement within the code I have where I put the *****
so if the icydate field is empty/null it opens one form, and if has a dete
it that feild opens the form I have already in the code.

ta Jon
 
A

Arvin Meyer [MVP]

I'd use a Select Case statement, but you can continue with the code you
have. To test for null, just wrap the code you want to use for that form in
the following:

If Len([Me.[Txt_reqONo] & vbNullString) = 0 Then
' Do something
Else
' Do something else
End If

using vbNullString as a constant, takes care of either Null or Empty.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Having trouble with code 2
Error with code for button 4
some subforms and combos blank 6
Get User 1
Password Box 4
filter with variable 1
Key Violation message 5
2 questions 1

Top