Query or Code ??

m1sund3st00d

New member
Local time
Today, 14:39
Joined
Aug 10, 2006
Messages
8
I want to set a y/n if a previous result is true or specific value. Is it more efficient/easier to use a query or code?
 
A query is generally always easier for the beignner than code. The more experienced programmer uses code.
 
Well I've always like a challenge.....

Here is what I am trying to do.

Code:
Private Sub Phone_AfterUpdate()

  Dim strSQL           As String
  Dim rsPhone           As DAO.Recordset
  Dim varInDNC           As Integer
    
  strSQL = "SELECT * From tblDNCList " & _
             "WHERE PhoneNum = '" & Me.Phone & "'"

    Set rsPhone = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
 
      varInDNC = Me.InDNC 
'<---- This line ^ gets a R-T 438 error------>

    If Not rsPhone.EOF Then
     varInDNC = -1
     MsgBox "This Phone Number is in a DNC Database."
      'What to do if they don't exist
      'MsgBox "End of File"
      
    Else
    
    If IsNull(Me.Phone) Then
    MsgBox "No Number Entered."
      'What to do if they do
         
       End If
    End If
 

  Set rsPhone = Nothing

End Sub
 
Assuming that the recordset would not be needed if the answer is false, you could:

Code:
If DCount("PhoneNum", "tblDNCList", "PhoneNum = '" & Me.Phone & "'") > 0 Then
    boolNumExists= True
Else
    boolNumExists = False
End If

If you don't need to create the recordset, don't. If you are using the NumExists boolean value as a pathway determinant, placing it in a recordset creates more overhead, declare it as a public variable instead and it will be accessible throughout the application.
 
Thanks for the reply.

?? All the code works except for the portion that I have added.

Code:
Dim varInDNC           As Integer

varInDNC = -1

forget the name, but another member provided me with the rest of the code.

My purpose for setting the Y/N is for nothing more than criteria for a query/report.

Before I hade a msgbox tell the users to enter "000-000-0000". I now need the number intact for future reference, and why i need an alternative method to exclude a number i dont wont.
 

Users who are viewing this thread

Back
Top Bottom