A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Unable To Read Value in Masked Textbox



 
 
Thread Tools Display Modes
  #1  
Old January 27th, 2009, 01:07 PM posted to microsoft.public.access.forms
techninut
external usenet poster
 
Posts: 2
Default Unable To Read Value in Masked Textbox

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
  #2  
Old January 27th, 2009, 03:10 PM posted to microsoft.public.access.forms
techninut
external usenet poster
 
Posts: 2
Default Unable To Read Value in Masked Textbox

I have discovered that I need to look at the .Value of the TextBox when
looking at one with a Mask.

I use a check string (checkStr) to see if a value is available. If not, then
I assume that the value was captured in the code above. If a value is found
then I use .Name to specify the field I am looking at and "='" & .Value & "'"
to apply the value. This seems to be working the way I expected it to.

So here is my updated code:

Private Sub cmdSearch_Click()
On Error Resume Next

Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
Me.txtSQL = ""

'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
Dim checkStr As String
checkStr = " --: " & .Value & " :-- "
If checkStr = " --: :-- " Then
' Do Nothing
Else
sWhereClause = sWhereClause & " and [" & .Name &
"]='" & .Value & "' "
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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.