Reading Textbox values from table and validating entry

  • Thread starter Thread starter Matt Williamson
  • Start date Start date
M

Matt Williamson

I have 2 things that I'm stuck on and would appreciate some assistance.

1. How can I read a value from a table and use it to populate a textbox when
a form is opened? Right now, I have 4 unbound textboxes on a form that a
user enters values into everytime the form opens. I'd like to check whether
or not a value exits in a table and write the table/value if it doesn't
exist. otherwise, if the table/values do exist, just populate the textboxes
with the appropriate values.

2. What is the best way to validate the textboxes in this case? I want to
display a message if the main button to perform the query from the data on
the form is pressed and the 4 textboxes are blank or contain incorrect data.

TIA

Matt
 
Here is a sample of code I received help on, following
through will show you how to pickup the table values.

***** Code Sample *****

On Error GoTo err_fopen

'Me.Modal = True
Me.txtQuarter = Format(Date - 91, "q")
Me.Frame55 = Me.txtQuarter
Me.cboYear = Format(Date, "yyyy")

Me.Command118.Visible = False
Me.Label119.Visible = False
Me.Command73.Visible = False
Me.Label74.Visible = False

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim txtVal As Integer
Dim FrmVal As String
Dim RowVal As Integer
Dim frm As Form

RowVal = DCount("*", "tl_HotSpotZC")
If RowVal > 30 Then
MsgBox "There are more than 30 Zipcodes in " &
Chr(10) _
& "table tl_HotSpotZC. Edit this table to a
maximum " & Chr(10) _
& "of 30 or less Zipcodes. Click return on
HotSpot " & Chr(10) _
& "form before editing Zipcode table. "
'DoCmd.Close acForm, "frmHotSpot"
DoCmd.OpenTable "tl_HotSpotZC", acViewNormal,
acEdit
Exit Sub
End If

Set dbs = CurrentDb
Set frm = Forms!frmHotSpot!

Set rst = dbs.OpenRecordset("Select
tl_HotSpotZC.HotSpZC FROM tl_HotSpotZC", dbOpenSnapshot)

txtVal = 0
With rst
.MoveLast
.MoveFirst

Do Until rst.EOF
'Debug.Print txtVal
'Debug.Print !HotSpZC & .AbsolutePosition + 1
FrmVal = "Text" & CStr(txtVal)
frm(FrmVal) = !HotSpZC
txtVal = txtVal + 2
.MoveNext
Loop

End With
rst.Close

***** End Code Sample *****

Exit_fopen:
Exit Sub

err_fopen:
ErrorRoutine
Resume Exit_fopen
 
Back
Top