Form Field Always Null Even When Showing Data

StacyinLV

Registered User.
Local time
Today, 10:04
Joined
May 3, 2015
Messages
10
The code below always displays opens form even when field being tested is null. Any ideas on how to fix that?



Private Sub Assign_Classes_Click()
On Error GoTo Err_Assign_Classes_Click

Dim stDocName As String
Dim msgboxstring As String
Dim stLinkCriteria As String
Me.name_found.Requery


If Not IsNull(Me.name_found) Then

DoCmd.SetWarnings False
DoCmd.OpenQuery "Qry_Load_Client_Classes"
DoCmd.SetWarnings True

stDocName = "Frm_Class_Selection"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
msgboxstring = "Client Not Found"
MsgBox (msgboxstring)
End If


Exit_Assign_Classes_Click:
Exit Sub

Err_Assign_Classes_Click:
MsgBox Err.Description
Resume Exit_Assign_Classes_Click

End Sub
 
Try


If Len(Me.name_found & vbNullString) > 0 Then
 
I got the error. "The expression you entered has a field, control or property that Microsoft Access can't find"
 
Double check the name of the textbox; I thought I copied it correctly.
 
Thanks for responding to my question. i did check. Could it be that i have an old or restricted version of VB? i have 7.1 for applications it says.

The text box name is correct, yet the command does not work.
 
If "The expression you entered has a field, control or property that Microsoft Access can't find" is trigered by If Len(Me.name_found & vbNullString) > 0 Then (always write WHICH LINE CAUSED THE ERROR!) then no, you do not have a textbox named name_found on that form. Access doesn't lie.

"the command does not work. " contains absolutely no useful information for people you ask for help. Always state what you did, what you expected and then what the outcome was.
 
Can you post the db here?
 
It is a list box. does that make a difference? The code does not go back to highlight the error.
 
It confirms the name of the listbox, but doesn't give me anything to play with to try and resolve the problem. I would have thought your original code would work with a listbox. You can try this test instead:

If Me.name_found.ItemsSelected.Count > 0 Then
 
you are testing for null, but maybe you have a zero length string - in which case the null test will fail

make it

If Not nz(Me.name_found,"")="" Then

(which is the same as paul (pbaldy) said with slightly different syntax
 
I think it must be Office 360. i have 2007 version of access. let me try that.

Thanks all...
 
Are you sure? That counts the number of items in the listbox, not that anything was selected.
 
Yes. when query runs, it displays results in name_found list. If name_found is blank and they click schedule button, error message displays. Otherwise, show list of available courses.
 
There is probably a better way to do this. I will never have more than one record in name_found. I couldn't get textbook to work.
 
I don't see anything setting a textbox; what's the control source?
 

Users who are viewing this thread

Back
Top Bottom