momaw nadon
Registered User.
- Local time
- Yesterday, 16:31
- Joined
- Apr 19, 2013
- Messages
- 10
I'm still learning Access 2010 and having issues getting my buttons to work the way I need. I'm working on a simple address database.
First issue is with my edit/save button. On form load, my fields are locked and my button will read "edit". After clicking, my fields are unlocked, my search features are locked, and my button reads "save" just how I need it to. The issue happens when I try and save the field edits, lock fields, return search features, and get button to read "edit" again. I know I need to add some code into what I already have, but I'm running into a wall as I have tried many options to get it to work. Here is the code for this button:
Second issue is with my report button. I have not been able to get this to work once. I have done many searches on single record reports, and have found the same code every time. I added that code into my database, but can't seem to get it to work. In my database there are two address (shipping and work location) which I would like to print out together. I have the work location on the main form and the shipping on a subform. There are and upwards of 150 locations I will have in my database, so I really need to be able to single out one set for a job. Though I'm wondering if this is even possible. Here is the code I'm working with:
Any help or suggestions to solve my issues would be greatly appreciated and I thank you for any assistances.
MN
First issue is with my edit/save button. On form load, my fields are locked and my button will read "edit". After clicking, my fields are unlocked, my search features are locked, and my button reads "save" just how I need it to. The issue happens when I try and save the field edits, lock fields, return search features, and get button to read "edit" again. I know I need to add some code into what I already have, but I'm running into a wall as I have tried many options to get it to work. Here is the code for this button:
Code:
Private Function Lockdown() 'locks controls at load
Dim tb As Control
Dim cb As Control
Dim subf As Control
For Each tb In Me.Controls
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = 13882323
End If
Next tb
For Each cb In Me.Controls
If TypeOf cb Is ComboBox Then
cb.Locked = False
cb.BackColor = 16777215
End If
Next cb
For Each subf In Me.Controls
If TypeOf subf Is SubForm Then
subf.Locked = True
End If
Next subf
End Function
Private Function UnlockFields() 'unlocks controls
Dim tb As Control
Dim cb As Control
Dim subf As Control
For Each tb In Me.Controls
If TypeOf tb Is TextBox Then
tb.Locked = False
tb.BackColor = 16777215
End If
Next tb
For Each cb In Me.Controls
If TypeOf cb Is ComboBox Then
cb.Locked = True
cb.BackColor = 13882323
End If
Next cb
For Each subf In Me.Controls
If TypeOf subf Is SubForm Then
subf.Locked = False
End If
Next subf
End Function
Private Sub cmdsiteedit_Click()
Call UnlockFields
Me.siteid.Enabled = False
Me.local.Enabled = False
If cbositesearch.Enabled = True Then
cmdsiteedit.Caption = "Save"
Else
cmdsiteedit.Caption = "Edit"
End If
End Sub
Second issue is with my report button. I have not been able to get this to work once. I have done many searches on single record reports, and have found the same code every time. I added that code into my database, but can't seem to get it to work. In my database there are two address (shipping and work location) which I would like to print out together. I have the work location on the main form and the shipping on a subform. There are and upwards of 150 locations I will have in my database, so I really need to be able to single out one set for a job. Though I'm wondering if this is even possible. Here is the code I'm working with:
Code:
Private Sub cmdrptadd_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "rptSiteAdd"
strCriteria = "siteid='" & Me!siteid & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End Sub
Any help or suggestions to solve my issues would be greatly appreciated and I thank you for any assistances.
MN