Record requery

cmw

Registered User.
Local time
Today, 22:35
Joined
Jan 21, 2008
Messages
46
I enter Primarykey value in textbox , Find record textboxvalue wise and work form requery display it. How will do? I try below this.

Dim db As DAO.Database
Dim strSQL As String
Set db = CurrentDb
Dim rs As Object
strSQL = "SELECT * " & _
" FROM [Ledger] " & _
"WHERE ([Ledger].RID)= " & Me.RID & "; "
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.FindFirst "[RID] = " & Me![RID] & " "
 
Where do you want to display the Data? Just house it in a RecordSet or do you want to display the data in a Form?

Maybe you are thinking more in the lines of this:
Code:
Private Sub Command1_Click()
   [COLOR="DarkGreen"]'Declare Variables[/COLOR]
   Dim qryDef As QueryDef
   Dim StrgSQL As String

   [COLOR="DarkGreen"]'Hold the desired Query String[/COLOR]
   StrgSQL = "SELECT * FROM [Ledger] WHERE ([Ledger].RID)= " & Me.RID & "; "
   
   [COLOR="DarkGreen"]'Create a Temporary Query[/COLOR]
   Set qryDef = CurrentDb.CreateQueryDef("tmpQuery", StrgSQL)
   
   [COLOR="DarkGreen"]'Run the Query[/COLOR]
   DoCmd.OpenQuery "tmpQuery"
   
   [COLOR="DarkGreen"]'Delete the Query. Don't need it anymore.[/COLOR]
   CurrentDb.QueryDefs.Delete "tmpQuery"
End Sub

.
 
Thanks CyberLynx, I want enter billno in a textbox, if billno is available,that billno record fetch in form,otherwise nothing. Its billno is primarykey.
i.e Billno is available form refresh update mode,else addnew mode.
 
I don't really know your complete situation there but perhaps what you may be better off to do in this case is have the Customer names within a Combo Box. Then based on the selection of the Customer Name, all the outstanding Bill Numbers (billno) for that Customer are displayed withing another Combo Box or List.

When a Bill Number is selected from the list then the record is populated into Form.

In any case....something just basic to try within the BeforeUpdate event of your TextBox:

Me.RecordSource = "SELECT * FROM [Ledger] WHERE ([Ledger].RID)=" & Me.RID & ";"


:confused:

.
 
Sorry for late reply
Its not work, the below error display
" The value you entered doesn't meet the validation rule defined for the field or control "
How it solve?
 

Users who are viewing this thread

Back
Top Bottom