Benginner2212
Member
- Local time
- Today, 07:42
- Joined
- Apr 6, 2023
- Messages
- 52
I have two forms where I would like to have the combo boxes and text boxes based on how a user opens the form. Since I have two forms, I thought that I would write a function but I am having issues. First off, I know that my code in the function to lock the text box is wrong, but I can get the function to run in the first place to begin trouble shooting that issue.
So the code that I am trying execute in the function is
If my understanding is correct, since a text box is an object I have to pass it by reference and passing by reference is the default in Access I don't think that I needed to have it written as
And then is the main code I am trying to call the function like this:
Private Sub Form_Load()
Dim cableBoxColor As Long
Dim cableTxtCtrl As Control
Dim cableCboCtrl As Control
cableBoxColor = RGB(211, 211, 211)
If Me.OpenArgs = "NewRecord" Then
Me.cboCategoryFilter.Visible = False
Me.txtCableNumber.Visible = False
Me.btnClearSearch.Enabled = False
Me.btnClearSearch.Visible = False
ElseIf Me.OpenArgs = "SearchRecord" Then
Me.cboCategoryFilter.Visible = True
Me.txtCableNumber.Visible = True
Me.btnClearSearch.Enabled = True
Me.btnClearSearch.Visible = True
Me.btnAddCableCategory.Visible = False
Me.btnAddSourceRack.Visible = False
Me.btnAddDestinationRack.Visible = False
Me.btnSaveRecord.Caption = "Update"
lockTxtBox Me.cableSouceDescription
ElseIf Me.OpenArgs = "DeleteRecord" Then
Me.cboCategoryFilter.Visible = True
Me.txtCableNumber.Visible = True
Me.btnClearSearch.Enabled = True
Me.btnClearSearch.Visible = True
Me.btnSaveRecord.Caption = "Delete"
Me.btnAddCableCategory.Visible = False
Me.btnAddSourceRack.Visible = False
Me.btnAddDestinationRack.Visible = False
End If
End Sub
When the code runs, I get an Expected Variable or procedure, not module error.
I also tried
hoping that would work, but I got a syntax error which I am guessing I got because I don't need to use call.
Not sure what I am doing wrong.
So the code that I am trying execute in the function is
Code:
Public Sub lockTxtBox(txtBox As TextBox)
Dim txtBoxColor As Long
Dim txtCtrl As Control
txtBoxColor = RGB(211, 211, 211)
For Each txtCtrl In Me.Controls
If TypeOf txtCtrl Is TextBox Then
txtCtrl.BackColor = BoxColor
txtCtrl.Locked = True
End If
Next
End Sub
If my understanding is correct, since a text box is an object I have to pass it by reference and passing by reference is the default in Access I don't think that I needed to have it written as
Code:
Public Sub (By REF txtBox As TextBox)
And then is the main code I am trying to call the function like this:
Private Sub Form_Load()
Dim cableBoxColor As Long
Dim cableTxtCtrl As Control
Dim cableCboCtrl As Control
cableBoxColor = RGB(211, 211, 211)
If Me.OpenArgs = "NewRecord" Then
Me.cboCategoryFilter.Visible = False
Me.txtCableNumber.Visible = False
Me.btnClearSearch.Enabled = False
Me.btnClearSearch.Visible = False
ElseIf Me.OpenArgs = "SearchRecord" Then
Me.cboCategoryFilter.Visible = True
Me.txtCableNumber.Visible = True
Me.btnClearSearch.Enabled = True
Me.btnClearSearch.Visible = True
Me.btnAddCableCategory.Visible = False
Me.btnAddSourceRack.Visible = False
Me.btnAddDestinationRack.Visible = False
Me.btnSaveRecord.Caption = "Update"
lockTxtBox Me.cableSouceDescription
ElseIf Me.OpenArgs = "DeleteRecord" Then
Me.cboCategoryFilter.Visible = True
Me.txtCableNumber.Visible = True
Me.btnClearSearch.Enabled = True
Me.btnClearSearch.Visible = True
Me.btnSaveRecord.Caption = "Delete"
Me.btnAddCableCategory.Visible = False
Me.btnAddSourceRack.Visible = False
Me.btnAddDestinationRack.Visible = False
End If
End Sub
When the code runs, I get an Expected Variable or procedure, not module error.
I also tried
Code:
Call lockTxtBox Me.cableSouceDescription
hoping that would work, but I got a syntax error which I am guessing I got because I don't need to use call.
Not sure what I am doing wrong.