2016-07-12 26 views
0

有一個銷售建議訪問數據庫,用於具有可以將較早對應的提案編號作爲參考的字段的工作。如果您點擊該字段下方的某個按鈕,它會直接將您帶到較早的記錄。有時候我們在數字A-12345,E-12345前面有一個前綴,或者它可能只是12345.訪問2013,從搜索字段中提取數字

我需要能夠在沒有字母的情況下抓住數字,並且 - 爲了搜索起作用正確。由於

Here是我的屏幕

回答

0

的假設你有列建議和參考,並與對照txtReference和txtProposal單一形式的表格圖像,把這段代碼到你的表單按鈕的On_Click事件(I」 m使用DAO):

Dim strProposal As String 
Dim i As Integer 
Dim rs As DAO.Recordset 

If Len(Nz(Me.txtReference, "")) < 1 Then 
MsgBox "No reference number entered" 
Else 
For i = 1 To Len(Me.txtReference) 
     If IsNumeric(Mid(Me.txtReference, i, 1)) Then 
     strProposal = strProposal & Mid(Me.txtReference, i, 1) 
     End If 
Next 
End If 

Set rs = Me.RecordsetClone 
rs.MoveFirst 
rs.FindFirst "Proposal = '" & StrProposal & "'" 
If rs.NoMatch Then 
MsgBox "Original proposal not found" 
Else 
Me.Bookmark = rs.Bookmark 
Me.txtProposal.SetFocus 
End If 

rs.Close 
Set rs = Nothing 
+0

謝謝你Rene,我會看看這個,看看我可以如何實現它。感謝你的幫助。 – usatraveler

+0

在代碼中輸入拼寫錯誤。行rs.FindFirst「Proposal ='」&outstr&「'」應該讀取rs.FindFirst「Proposal ='」&strProposal&「'」,我編輯了代碼。 – Rene