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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|