Apr 10 2023 12:22 AM - edited Apr 10 2023 12:34 AM
Hello
I have a table Tb_ACCOUNTS am trying to create a form with a search button and i have written the VBA code below but am not getting any out put. what could be the challenge with my code.
Table
Form
Code:
O
Option Compare Database
Private Sub SearchButton_Click()
Dim rst As DAO.Recordset
Dim strsql As String
strsql = "Select FORACID,ACCT_NAME,SCHM_CODE,STAFF_PF From Tb_ACCOUNTS Where FORACID= " & Tx_Search_Acct.Value & ""
Set rst = CurrentDb.OpenRecordset(strsql)
If rst.EOF Then
MsgBox " No data found: Check Account open date"
Tx_Acct_Num.Value = Nothing
Tx_Acct_Name.Value = Nothing
Tx_Sch_code.Value = Nothing
Tx_PFNum.Value = Nothing
Else
Tx_Acct_Num.Value = rst.Fields("FORACID")
Tx_Acct_Name.Value = rst.Fields("ACCT_NAME")
Tx_Sch_code.Value = rst.Fields("SCHM_CODE")
Tx_PFNum.Value = Fields("STAFF_PF")
End If
rst.Close
Set rst = Nothing
End Sub
Apr 10 2023 02:02 AM
Apr 10 2023 05:13 AM
@KINENE_JAMIL As Arnel pointed out, the problem is that your search field, FORACID, is a text field, not a number. You can tell that from the screenshot because it is left aligned, whereas the number field next to it, ACCT_SOL_II, is right aligned.
Numbers do not need delimiters, text strings do need delimiters.
Apr 10 2023 05:56 AM
Apr 10 2023 05:56 AM
Apr 10 2023 06:06 AM
Apr 11 2023 11:53 PM
Thank you.
it helped me locate the error. i had missed the Tx_PFNum.Value = rst.Fields("STAFF_PF").
Now its working.