Link a checkbox on my form to another table

So you have a field in a table named ShortID and a function on this form named shortID()? That's a formula for confusing Access and it does not take too much to confuse it, believe me. Is there a chance of renaming one of them to maybe shortID2 or something.

On a separate subject, do you have Name Auto-Correct turned off? Tools>Options>General tab.
 
Okay cool i renamed the field in that table to sID instead of ShortID :cool:

No. Autocorrect is turned on

still same error *sighs
 
Let's try this:
Code:
Private Sub chkNoSupportHrs_Click()
On Error GoTo Err_ChkBox_Click
Dim MySQL As String
[b]Dim db As DAO.Database
Set db = CurrentDB()[/b]

If Me.chkNoSupportHrs Then
   '-- CheckBox going to "Checked" state
   MySQL = "Insert Into tblNoSupportHrs(sID,WeekEnding) " & _
        "Values(" & Me.txtResource & ", """ & Me.Text18 & """)"
Else
   '-- CheckBox going to "UnChecked" state
   MySQL = "DELETE * FROM tblNoSupportHrs WHERE [sID] = " & Me.txtResource
End If

[b]'MsgBox MySql
db.Execute MySQL, dbFailOnError[/b]

Exit_ChkBox_Click:
   [b]Set db = Nothing[/b]
   Exit Sub

Err_ChkBox_Click:
   MsgBox "Error No:    " & Err.Number & vbCr & _
   "Description: " & Err.Description
   Resume Exit_ChkBox_Click

End Sub
 
wooohooo...!!! It works :D :D

You are great. Thank alooott
icon14.gif

God bless your heart *muah
 
I'm glad I could help. I don't know if you are using any ADO but if not, you might try unchecking the reference to ActiveX and recompile. If there are no errors then leave it unchecked. Post back if you need further assistance.
 
RuralGuy said:
I'm glad I could help. I don't know if you are using any ADO but if not, you might try unchecking the reference to ActiveX and recompile. If there are no errors then leave it unchecked. Post back if you need further assistance.

Thanks again for all your time, help and patience :)

I have one more question thing :o

I notice that when i have a previous week selected, and i go into this form. The data from the previous week is populated in the form already (the form is bound to a table).

But if the person checked the chkNoSupportHrs checkbox lastweek and they go in a week after. The checkbox is not checked (it is not saved).
Do you think it will be wise for me to have bound this table also (that's if you can bound 2 tables).
Or
Attach VBA to the onload event of this form, so that it checks the tblNoSupportHrs table and if there's a match for that person for that week, then it keeps box checked.

What's do you think is the wise thing to do here?
 
I'm sorry MsLady, but I don't really understand your forms and tables. I've just been troubleshooting a specific problem so far. Since you have no True/False field in the tblNoSupportHrs table you are left with adding some VBA to the OnLoad event to set up your form. At least as far as I can tell knowing what I know so far. I hope that helps.
 
RuralGuy said:
I'm sorry MsLady, but I don't really understand your forms and tables. I've just been troubleshooting a specific problem so far. Since you have no True/False field in the tblNoSupportHrs table you are left with adding some VBA to the OnLoad event to set up your form. At least as far as I can tell knowing what I know so far. I hope that helps.

Okay cool. Thanks you have been soo helpfull Rural guy :)

Soo, I decided to add code to the onload event. One more thing:

How do i tell it to check my box in vba?

Me.chkNoSupportHrs (isn't working)
chkNosupportHrs.checked ???? um obviously not :rolleyes:

Feel free to curse me :D

.
 
Sorry MsLady, I used a shorthand before. The longhand would be:
If Me.chkNoSupportHrs = True Then

To set it you would code:
Me.chkNoSupportHrs = True (or False to show UnChecked)
 
Error 3065, "cannot execute a select query"

*ahem
Rural Guy, i have come again.. :eek:
LOL.. i refuse to go away :o

As you may know already, I am attaching this code to the onload event of my form bound to a table.
And i want it to check a chkbox on this form if some data on this form (Me.Text18, Me.txtResource) exists in "another" table (tblNoSupportHrs)

Here is what i have in my onload event:

Code:
On Error GoTo Err_ChkBox_Click
Dim db As DAO.Database
Set db = CurrentDb()
Dim MySQL As String, DQ As String
DQ = """"

    MySQL = "SELECT [WeekEnding] from tblNoSupportHrs WHERE [sID] = " & DQ & Me.txtResource & DQ & _
        " And [WeekEnding] = " & DQ & Me.Text18 & DQ & ";"

        If Me.Text18 = MySQL Then
            Me.chkNoSupportHrs = True
        Else
        End If
db.Execute MySQL, dbFailOnError

Exit_ChkBox_Click:
    Set db = Nothing
    Exit Sub

Err_ChkBox_Click:
   MsgBox "Error No:    " & Err.Number & vbCr & _
   "Description: " & Err.Description
   Resume Exit_ChkBox_Click

End Sub

However, i get this error: When i load my form.
Error 3065, "cannot execute a select query"

I am aware that the Execute method can be used for action queries only (UPDATE, INSERT, DELETE, ALTER, ...) and it won't work since i am trying to "SELECT" here.

Someone suggested i will need to play with my Recordset or the DLookUp function.
I don't know how to do this.
Any thoughts, suggestions, ideas, curses? anything :o

sorry for my trouble :o
 
This should work for you:
Code:
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim db As DAO.Database
Dim MyRs As DAO.Recordset
Dim MySQL As String

Set db = CurrentDb()

MySQL = "SELECT * from tblNoSupportHrs WHERE [sID] = " & Me.txtResource & _
        " And [WeekEnding] = '" & Me.Text18 & "';"

Set MyRs = db.OpenRecordset(MySQL, dbOpenDynaset)

If MyRs.RecordCount > 0 Then
   Me.chkNoSupportHrs = True
Else
   Me.chkNoSupportHrs = False
End If

Exit_Form_Load:
   On Error Resume Next
   MyRs.Close
   Set MyRs = Nothing
   Set db = Nothing
   Exit Sub

Err_Form_Load:
   MsgBox "Error No:    " & Err.Number & vbCr & _
   "Description: " & Err.Description
   Resume Exit_Form_Load

End Sub
 
yipiee!! works nicely :D :D

YOU ARE BRILLIANT!!!
Thanks again. I owe you alot :)


That about wraps it up for this task.
Thanks for all your help and yoru patience *hugs
 
Just glad to be of service Ma'm. :cool: Thanks for the kind words.
 

Users who are viewing this thread

Back
Top Bottom