runtime 3075 when user doesnt select a ref

krowe

Registered User.
Local time
Today, 05:58
Joined
Mar 29, 2011
Messages
159
I have a search form and the user has to select a case ref before clicking an action.

if they don't select a case it throws up an error so i'm trying to put in some error handling.

this is what i have, but it deosnt seem to be doing the job, please can someone let me know where im going wrong, i'm sure its something really simple:

Code:
Private Sub Command5_Click()
 
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmUpdateCaseStep2"
    
    stLinkCriteria = "[ID]=" & Me![SearchResults]
    
If stLinkCriteria = "" Or Null Then
    
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
 
    ' Promt
    strPrompt = "Please select a client first"
 
    ' Dialog's Title
    strTitle = "Oops"
 
    'Display MessageBox
    iRet = MsgBox(strPrompt, vbOKOnly, strTitle)
    
Else
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "frmUpdateCaseStep1", acSaveYes
    
End If
    
End Sub

Thanks
 
Instead of using..
Code:
If stLinkCriteria = "" Or Null Then
Try this..
Code:
[COLOR=SeaGreen]'I would personally recommend this, as this has the ability to capture Empty string and NULL values. [/COLOR]
If Len(stLinkCriteria & "")=0 Then
or
Code:
If stLinkCriteria = "" Or IsNull(stLinkCriteria) Then
 
The only thing is that stLinkCriteria is declared as string, and a string can never be Null.

Besides, according to your code your string is never empty,so you are testing the wrong thing.

Follow this recipe (Section Debugging Tips) for debugging http://www.access-programmers.co.uk/forums/showthread.php?t=149429
 
Oops.. did not see that there.. spikepl is right.. the declaration you have
Code:
stLinkCriteria = "[ID]=" & Me![SearchResults]
makes it a string with a length always greater than 1.. so the code given above will not work.. so instead, work on checking the length of the [SearchResults]
Code:
If Len(Me.[SearchResults] & "")=0 Then
 
Thats great Paul, works fine now.

Thanks to you both
 

Users who are viewing this thread

Back
Top Bottom