Update a Textbox on a Form with Field Value via VB.

T

TimWillDoIt

Hello,

I've created some Access apps, but I've very new to Visual Basic Event
Procedures. I want to take the value of a table field and put it in a
Textbox on my form when an object on the form is clicked.

I'm sure the basic VB procedure is good, I just need the correct syntax.
Below is that section of my code. The line in question is right under the
MsgBox line. "txtLimitedAccCost(JobCond)" is the name of my Textbox on the
form named "frmJobCost8". The value I want to place in the Textbox is in the
field, "LimitedAccess" in table "tblJobCondCosts"

If I haven't totally confused everyone, can someone give me the correct
syntax to put that value in that Textbox? Thanks.


Private Sub chkLimitAcc_JobCond__Click()
On Error GoTo Err_chkLimitAcc_JobCond__Click

MsgBox "It Worked!", 1
frmJobCost8.txtLimitedAccCost(JobCond) = tblJobCondCosts.LimitedAccess

Exit_chkLimitAcc_JobCond__Click:
Exit Sub

Err_chkLimitAcc_JobCond__Click:
MsgBox Err.Description
Resume Exit_chkLimitAcc_JobCond__Click
End Sub
 
T

TimWillDoIt

I'm making some progress. When I change the line in question to read:
Me.txtLimitedAccCost_JobCond_ = 50

I can insert the number 50 into the Textbox when I click the form object.
But I'm still struggling to get the contents of the table field into that
Textbox. What's the correct syntax? Thanks.
 
F

fredg

Hello,

I've created some Access apps, but I've very new to Visual Basic Event
Procedures. I want to take the value of a table field and put it in a
Textbox on my form when an object on the form is clicked.

I'm sure the basic VB procedure is good, I just need the correct syntax.
Below is that section of my code. The line in question is right under the
MsgBox line. "txtLimitedAccCost(JobCond)" is the name of my Textbox on the
form named "frmJobCost8". The value I want to place in the Textbox is in the
field, "LimitedAccess" in table "tblJobCondCosts"

If I haven't totally confused everyone, can someone give me the correct
syntax to put that value in that Textbox? Thanks.


Private Sub chkLimitAcc_JobCond__Click()
On Error GoTo Err_chkLimitAcc_JobCond__Click

MsgBox "It Worked!", 1
frmJobCost8.txtLimitedAccCost(JobCond) = tblJobCondCosts.LimitedAccess

Exit_chkLimitAcc_JobCond__Click:
Exit Sub

Err_chkLimitAcc_JobCond__Click:
MsgBox Err.Description
Resume Exit_chkLimitAcc_JobCond__Click
End Sub

This code resides in the frmJobCost8 code module?

Me![txtLimitedAccCost(JobCond)] =
DLookUp("[LimitedAccess]","tblJobCondCosts")

The above assumes there is only one record in the tblJobCondCosts
table.
However, if the table can have more than one record, you need to add a
where clause (without the word Where) to the above to find the correct
record.
For example ....
=DLookUp("[LimitedAccess]","tblJobCondCosts","[RecordID] = " &
[SomeControlOnForm])

Look up DLookUp as well as "Where Clause" and also "Restrict data to a
subset of records" in VBA help.
 
T

TimWillDoIt

That did it. You are AWESOME. Thank you. I haven't quite figured out how
to make most effective use of the documentation. I've started going through
some tutorials, but all I can find are real basic ones. You've been a
tremendous help.


fredg said:
Hello,

I've created some Access apps, but I've very new to Visual Basic Event
Procedures. I want to take the value of a table field and put it in a
Textbox on my form when an object on the form is clicked.

I'm sure the basic VB procedure is good, I just need the correct syntax.
Below is that section of my code. The line in question is right under the
MsgBox line. "txtLimitedAccCost(JobCond)" is the name of my Textbox on the
form named "frmJobCost8". The value I want to place in the Textbox is in the
field, "LimitedAccess" in table "tblJobCondCosts"

If I haven't totally confused everyone, can someone give me the correct
syntax to put that value in that Textbox? Thanks.


Private Sub chkLimitAcc_JobCond__Click()
On Error GoTo Err_chkLimitAcc_JobCond__Click

MsgBox "It Worked!", 1
frmJobCost8.txtLimitedAccCost(JobCond) = tblJobCondCosts.LimitedAccess

Exit_chkLimitAcc_JobCond__Click:
Exit Sub

Err_chkLimitAcc_JobCond__Click:
MsgBox Err.Description
Resume Exit_chkLimitAcc_JobCond__Click
End Sub

This code resides in the frmJobCost8 code module?

Me![txtLimitedAccCost(JobCond)] =
DLookUp("[LimitedAccess]","tblJobCondCosts")

The above assumes there is only one record in the tblJobCondCosts
table.
However, if the table can have more than one record, you need to add a
where clause (without the word Where) to the above to find the correct
record.
For example ....
=DLookUp("[LimitedAccess]","tblJobCondCosts","[RecordID] = " &
[SomeControlOnForm])

Look up DLookUp as well as "Where Clause" and also "Restrict data to a
subset of records" in VBA help.
 
J

John W. Vinson

I'm sure the basic VB procedure is good, I just need the correct syntax.
Below is that section of my code. The line in question is right under the
MsgBox line. "txtLimitedAccCost(JobCond)" is the name of my Textbox on the
form named "frmJobCost8". The value I want to place in the Textbox is in the
field, "LimitedAccess" in table "tblJobCondCosts"

I presume that tblJobCondCosts can have any number of records. Do you care
WHICH record gets displayed? You can't just refer to a table in that way.

If the code is running on the form frmJobCost8, I'd suggest *SOMETHING LIKE*

Me![txtLimitedAccCost(JobCond)] = DLookUp("LimitedAccess, _
"tblJobCondCosts", "<some criteria string identifying the record")

See the online help for DLookUp. If the code is in a standard module or some
other form's module, then replace the shortcut Me! with the explicit

Forms!frmJobCost8!

If tblJobCondCosts is part of the form's Recordsource you may not need
DLookUp. Please explain the context.
 
T

TimWillDoIt

John,

In this particular instance, there is only one record. tblJobCondCosts
is a list of costs for various conditions. Since I originally didn't know
how i was going to accomplish what i wanted, I created a field for each
condition, the contents of the field being the cost of that condition.

Next time, now that i know how to specify which record, i will just
create a two-field table; one for the condition name and one for the
condition cost. Thank you for your assistance and input.

Tim

John W. Vinson said:
I'm sure the basic VB procedure is good, I just need the correct syntax.
Below is that section of my code. The line in question is right under the
MsgBox line. "txtLimitedAccCost(JobCond)" is the name of my Textbox on the
form named "frmJobCost8". The value I want to place in the Textbox is in the
field, "LimitedAccess" in table "tblJobCondCosts"

I presume that tblJobCondCosts can have any number of records. Do you care
WHICH record gets displayed? You can't just refer to a table in that way.

If the code is running on the form frmJobCost8, I'd suggest *SOMETHING LIKE*

Me![txtLimitedAccCost(JobCond)] = DLookUp("LimitedAccess, _
"tblJobCondCosts", "<some criteria string identifying the record")

See the online help for DLookUp. If the code is in a standard module or some
other form's module, then replace the shortcut Me! with the explicit

Forms!frmJobCost8!

If tblJobCondCosts is part of the form's Recordsource you may not need
DLookUp. Please explain the context.
 
J

John W. Vinson

In this particular instance, there is only one record. tblJobCondCosts
is a list of costs for various conditions. Since I originally didn't know
how i was going to accomplish what i wanted, I created a field for each
condition, the contents of the field being the cost of that condition.

Next time, now that i know how to specify which record, i will just
create a two-field table; one for the condition name and one for the
condition cost. Thank you for your assistance and input.

Good move... and glad to be of help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top