Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2007, 08:21 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

The problem with the Else statement is that there is NO If statement preceeding it that is not already closed by an End If.

You have:

If Then
End If

Else
End If

When you should have:

If Then
Else
End If

We can't help unless you post ALL of the code on the event that is causing the problem.


2. If "SalesID" is text, and PKSalesID is a number, you are bound to a number. SO the syntax does not require ' ' .
Assuming your PKSalesID is an autonumber and there are no duplicates, then this is fine:

sSql = "Select * From tblQuote Where [SalesID] = " & ipkSalesID & _
    " AND [Date] = #" & dtDate & "#"

Are you having problems with that?





mmcdonal
 
Old February 27th, 2007, 09:49 AM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default

1. Here is the Code exactly as it is in the Form for the event. I followed your template best I could. I colored the Debug error in red and the popup problem in green. reminder about the popup problem: The msgBox popsup even though the PKSalesID is chosen. You told me to place the Code:

Datecreated = Date()

I have a Date field that is the Date created but the default value is already Date(). Do I still need to place your code in there?


Private Sub cmdCreateQuote_Click()
If IsNull(Me.QuoteNumber) Or Me.QuoteNumber = "" Then
    Dim sString, sSql As String
    Dim rs As ADODB.Recordset
    Dim ipkSalesID, i As Integer
    Dim dtDate As Date

dtDate = Date
    If IsNull(QuoteNumber) Or Me.QuoteNumber = "" Then
    MsgBox "Please select your SalesID", vbCritical Exit Sub
Else
    ipkSalesID = Me.PKSalesID
End If

sSql = "Select * From Quote Where [PKSalesID] = " & ipkSalesID & _
    " AND [Date] = #" & dtDate & "#"
Set rs = New ADODB.Recordset
rs.Open sSql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic

i = 1

   Do Until rs.EOF
     i = i + 1
   rs.MoveNext
   Loop
    End If

    rs.Close
    sString = "Q-" & Me.PKSalesID & "-" & CStr(dtDate) & " (" & i & ")"
    Me.QuoteNumber = sString

Else
MsgBox "There is already a Quote Number.", vbCritical
End If

End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with formula Juan0214 Access 4 August 1st, 2008 07:25 AM
Help with formula 2 Juan0214 Access 3 July 10th, 2008 06:52 PM
formula sinha Crystal Reports 1 October 26th, 2005 12:53 PM
Help with a formula Corey Access 2 October 20th, 2005 10:48 AM
Formula Ned Pro VB 6 2 September 10th, 2003 10:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.