How to Display A Value in the Form? (1 Viewer)

JithuAccess

Member
Local time
Today, 11:02
Joined
Mar 3, 2020
Messages
297
Hello Guys,

I think I solved this with VBA Code. I have put the following code:

Code:
Private Sub ID_LostFocus()

Dim db As Database
Dim rst As Recordset
Dim STRSQL As String


Set db = CurrentDb()

STRSQL = "Select [Test.ID], [Test.Fname], [Test.DoB],[Test.Facility Name], [Test.City], [Test.State], [Test.Country] from Test where Test.ID=" & "'" & Me.ID & "';"


Set rst = db.OpenRecordset(STRSQL)

If rst.RecordCount = 0 Then
    MsgBox "This is a new Entry"
    Exit Sub
End If

Me.Fname = rst.Fields(1)
Me.DoB = rst.Fields(2)
Me.Facility_Name = rst.Fields(3)
Me.City = rst.Fields(4)
Me.State = rst.Fields(5)
Me.Country = rst.Fields(6)
Me.Recalc

End Sub

and this is what I am getting when I enter an ID and hit the Tab Button.

1612453361823.png



This may be a very foolish idea. But I think this will do our job.

Thanks very much for all of your help.
 

Attachments

  • 1612452984561.png
    1612452984561.png
    14.6 KB · Views: 94

theDBguy

I’m here to help
Staff member
Local time
Today, 10:02
Joined
Oct 29, 2018
Messages
21,358
Hello Guys,

I think I solved this with VBA Code. I have put the following code:

Code:
Private Sub ID_LostFocus()

Dim db As Database
Dim rst As Recordset
Dim STRSQL As String


Set db = CurrentDb()

STRSQL = "Select [Test.ID], [Test.Fname], [Test.DoB],[Test.Facility Name], [Test.City], [Test.State], [Test.Country] from Test where Test.ID=" & "'" & Me.ID & "';"


Set rst = db.OpenRecordset(STRSQL)

If rst.RecordCount = 0 Then
    MsgBox "This is a new Entry"
    Exit Sub
End If

Me.Fname = rst.Fields(1)
Me.DoB = rst.Fields(2)
Me.Facility_Name = rst.Fields(3)
Me.City = rst.Fields(4)
Me.State = rst.Fields(5)
Me.Country = rst.Fields(6)
Me.Recalc

End Sub

and this is what I am getting when I enter an ID and hit the Tab Button.

View attachment 88933


This may be a very foolish idea. But I think this will do our job.

Thanks very much for all of your help.
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom