T
techninut
I am trying to build a query using an Access Form. Inside the form are
several controls including some Masked Textboxes for Phone Numbers.
When I try to access the data entered into these Masked Textboxes, I get an
empty string.
Here is what I have so far:
Private Sub cmdSearch_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
'Initialize the Where Clause variable.
sWhereClause = " Where "
'Start the first part of the select statement.
sSQL = "select * from copy "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'The only Control you are using is the text box.
'However, you can add as many types of controls as you want.
Select Case .ControlType
Case acTextBox, acComboBox
.SetFocus
'This is the function that actually builds
'the clause.
If sWhereClause = " Where " Then
sWhereClause = sWhereClause & BuildCriteria(.Name,
dbText, .Text)
Else
sWhereClause = sWhereClause & " and " &
BuildCriteria(.Name, dbText, .Text)
End If
Case acCheckBox
If .Value = True Then
If sWhereClause = " Where " Then
sWhereClause = sWhereClause & "[" & .Name &
"]=True"
Else
sWhereClause = sWhereClause & " and [" & .Name &
"]=True"
End If
End If
End Select
End With
Next ctl
'Set the forms recordsource equal to the new
'select statement.
Me.txtSQL = sSQL & sWhereClause
Me.RecordSource = sSQL & sWhereClause
Me.Requery
End Sub
You can see that I am looking into the values of all TextBoxes, but it
ignores Masked Textboxes.
Any suggestions on what I am doing wrong or something I need to add??
Thank you in advance
several controls including some Masked Textboxes for Phone Numbers.
When I try to access the data entered into these Masked Textboxes, I get an
empty string.
Here is what I have so far:
Private Sub cmdSearch_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
'Initialize the Where Clause variable.
sWhereClause = " Where "
'Start the first part of the select statement.
sSQL = "select * from copy "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'The only Control you are using is the text box.
'However, you can add as many types of controls as you want.
Select Case .ControlType
Case acTextBox, acComboBox
.SetFocus
'This is the function that actually builds
'the clause.
If sWhereClause = " Where " Then
sWhereClause = sWhereClause & BuildCriteria(.Name,
dbText, .Text)
Else
sWhereClause = sWhereClause & " and " &
BuildCriteria(.Name, dbText, .Text)
End If
Case acCheckBox
If .Value = True Then
If sWhereClause = " Where " Then
sWhereClause = sWhereClause & "[" & .Name &
"]=True"
Else
sWhereClause = sWhereClause & " and [" & .Name &
"]=True"
End If
End If
End Select
End With
Next ctl
'Set the forms recordsource equal to the new
'select statement.
Me.txtSQL = sSQL & sWhereClause
Me.RecordSource = sSQL & sWhereClause
Me.Requery
End Sub
You can see that I am looking into the values of all TextBoxes, but it
ignores Masked Textboxes.
Any suggestions on what I am doing wrong or something I need to add??
Thank you in advance