Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update field in diffrent table

Status
Not open for further replies.

ZX188

Technical User
Mar 30, 2001
21
US
I have a combo box that needs to update a true/false check box in a different table based on the user selection of the combo box.
When the user selects something I need to up date the check box in the record that corresponds with the selection
How would I go about this?
Thanks
Kevin
 
Just a sample. You need to set the checkbox dependent on something on your form and I don't know what that would be.


Combo1_AfterUpdate

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

strSQL = "Select MyCheckField FROM tblOther " _
& "WHERE PriKey=" & Me.txtPriKeyValue & ";"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount <> 0 Then
rst!MyCheckField = True
Else
MsgBox &quot;Record not found!&quot;
End If

Set db = Nothing
Set rst = Nothing

End Sub Growth follows a healthy professional curiosity
 
Thanks for the help Sticking it gives me a good start
Kevin
 
I keep getting syntax error in FROM clause
This is what I have done

Private Sub PoNumber_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

strSQL = &quot;Select Closed From PoNumber&quot; & &quot;WHERE PriKey=&quot; & Me.[PoNumber.PoID] & &quot;;&quot;
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount <> 0 Then
rst!Closed = True
Else
MsgBox &quot;Record not gound&quot;
End If
Set db = Nothing
Set rst = Nothing
End Sub

PoNumber is the name of my ComboBox
Closed is my Check Box
PoNumber is My Table where the Check Box is
PoNumber.PoID is My PriKey on the form with my ComboBox
 


strSQL = &quot;Select Closed From PoNumber&quot; & &quot;WHERE PriKey=&quot; & Me.[PoNumber.PoID] & &quot;;&quot;

The best way to check on the SQL clause is to make a checkpoint on the next line after it is create and then use the debug window 'Debug.Print strSQL' which would have shown you:

Select Closed From PoNumberWHERE PriKey=PoID;

There are a couple problems as you see. First you need to add a space between PoNumber and WHERE. Second, if and only if the PoID is text you will need to delimit the text with quotes. If text, I would construct it like this:

strSQL = &quot;Select Closed From PoNumber WHERE PriKey=&quot; & &quot;&quot;&quot;&quot; & Me.[PoNumber.PoID] & &quot;&quot;&quot;&quot; & &quot;;&quot;

If numeric, I would construct it like this:

strSQL = &quot;Select Closed From PoNumber WHERE PriKey=&quot; & Me.[PoNumber.PoID] & &quot;;&quot;

Steve King
Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top