I've created a form where I can use a subform to load data from a query into textboxes so I can edit the data one at a time and update the database. This usually works fine except I have a run time error that randomly appears now and then - '-2147352567 (80020009)': The value you entered isn't valid for this field.'
If I stop running it and try running it again it usually works fine until the same run-time error appears. It's very inconsistent.
Private Sub btn_SelectAgency_Click()
If Not (Me.qryAgencyWithoutMileagesub.Form.Recordset.EOF And Me.qryAgencyWithoutMileagesub.Form.Recordset.BOF) Then
'get data to textbox control
With Me.qryAgencyWithoutMileagesub.Form.Recordset
Me.txt_AgencyID = .Fields("Agency ID")
Me.txt_AgencyName = .Fields("Agency Name")
Me.txt_Address1 = .Fields("Address 1")
Me.txt_Address2 = .Fields("Address 2")
Me.txt_City = .Fields("City")
Me.txt_Postcode = .Fields("Postcode")
Me.txt_AgencyMileage = .Fields("Mileage")
Me.txt_AgencyID.Tag = .Fields("Agency ID")
End With
End If
Me.txt_AgencyMileage = ""
End Sub
Private Sub btn_Update_Click()
If Me.txt_AgencyMileage = "" Then
MsgBox "No mileage added, add now"
Cancel = True
Else
CurrentDb.Execute "UPDATE EstateAgent_tbl SET EstateAgent_AgentMileage = '" & Me.txt_AgencyMileage & "' where EstateAgent_AgentID=" & Me.txt_AgencyID.Tag
Me.txt_AgencyID = ""
Me.txt_AgencyName = ""
Me.txt_Address1 = ""
Me.txt_Address2 = ""
Me.txt_City = ""
Me.txt_Postcode = ""
Me.txt_AgencyMileage = ""
End If
qryAgencyWithoutMileagesub.Form.Requery
If Me.qryAgencyWithoutMileagesub.Form.Recordset.RecordCount = 0 Then
MsgBox "No agencies without mileage"
DoCmd.Close
End If
End Sub
The error is on this line
Me.txt_AgencyID = .Fields("Agency ID")
I would appreciate any help with this, thank you :)
Dim rs As DAO.Recordset
Set rs = Me.qryAgencyWithoutMileagesub.Form.RecordsetClone
'get data to textbox control
With rs
If .RecordCount > 0 Then
Me.txt_AgencyID = .Fields("Agency ID")
Me.txt_AgencyName = .Fields("Agency Name")
Me.txt_Address1 = .Fields("Address 1")
Me.txt_Address2 = .Fields("Address 2")
Me.txt_City = .Fields("City")
Me.txt_Postcode = .Fields("Postcode")
Me.txt_AgencyMileage = .Fields("Mileage")
Me.txt_AgencyID.Tag = .Fields("Agency ID")
End If
End With
Set rs = Nothing
DoCmd.RefreshRecord
DoCmd.RunCommand acCmdUndo
'You can it try. That worked for me!
Try to exclude Null values:
If Not IsNull(.Fields("Agency ID").Value) Then
Me.txt_AgencyID.Value = .Fields("Agency ID").Value
End If
You may also try using the RecordsetClone:
Dim rs As DAO.Recordset
Set rs = Me.qryAgencyWithoutMileagesub.Form.RecordsetClone
'get data to textbox control
With rs
If .RecordCount > 0 Then
Me.txt_AgencyID = .Fields("Agency ID")
Me.txt_AgencyName = .Fields("Agency Name")
Me.txt_Address1 = .Fields("Address 1")
Me.txt_Address2 = .Fields("Address 2")
Me.txt_City = .Fields("City")
Me.txt_Postcode = .Fields("Postcode")
Me.txt_AgencyMileage = .Fields("Mileage")
Me.txt_AgencyID.Tag = .Fields("Agency ID")
End If
End With
Set rs = Nothing
Related
I am trying to find a way to move the data from a query to a table in MS Word. I have attached a picture of the document
Here's the situation: When we close a case out, we need to create a document that includes several pieces of demographic data from that case and list of important dates to that case. The table needs to have some borders (underline on the date), and it needs to be inserted midway through the document (I am thinking bookmarks are the way to go). The document may be sent to other providers off of our network. (I am really hoping the pic attached...)
I have tried using Power Query (which does not allow the user to set parameters or prompt for criteria).
My initial thoughts are to create a recordset from the query and then create a loop to insert the data into the table. However, all the posts I could find seem to only deal with creating the table in word as the sole object. I also can't find how to point the recordset to a bookmark or particular table. The user will generate the document from Access (Right now, I have it where it will put certain dates, like open and close, into the corresponding Form Field in Word template, but I'm stuck at this juncture).
I have minor programming knowledge, just enough to be known as the local expert, when I am merely the only programming fish in the small pond. I would be happy to pointed in the right direction or given some code snippets (I would like to understand why/how they work).
With gratitude, I want to post the code for the solution. Of course, there is probably a better way to do it, but the solution works, and best of all I know why it works.
Public Function concatData() As String
Dim retVal As String
Dim rsHeader As Long, rsCounter As Long
Dim rs As DAO.Recordset
Dim Val As String
Dim strSQL As String
'This code puts the query into a recordset, which is then formatted into a table later
Val = [Forms]![FrmAllTracker]![CaseID]
strSQL = "Select * From QryTrackerInitRecRecv WHERE [CaseID] = " & Val
Set rs = CurrentDb.OpenRecordset(strSQL)
'Get headers
'For rsHeader = 0 To rs.Fields.Count - 1
' retVal = retVal & rs.Fields(rsHeader).Name & vbTab
'Next
'Replace last TAb with a carriage return
'retVal = Left(retVal, Len(retVal) - 1) & vbCr
Do While Not rs.EOF
'Get all records
For rsCounter = 0 To rs.Fields.Count - 1
retVal = retVal & rs.Fields(rsCounter).Value & vbTab
Next
retVal = Left(retVal, Len(retVal) - 1) & vbCr
rs.MoveNext
Loop
concatData = retVal
End Function
Private Sub BtnGenTracker_Click()
If IsNull(Me.CaseClosed) Then
MsgBox "Please Enter a Close Date", _
vbOKOnly + vbInformation
Exit Sub
End If
' Create pointers to Word Document
Dim wd As Word.Application
Dim doc As Word.Document 'doc As Word.Document
Dim bolOpenedWord As Boolean
Dim rng As Range
Dim Tbl As Word.Table
Dim MDate As String
MDate = Format([CaseOpen], "mm-dd-yyyy")
' Get pointer to Word Document
On Error Resume Next
Set wd = GetObject(, "Word.Application")
If Err.Number = 429 Then
' If Word is not opened, open it
Set wd = CreateObject("Word.Application")
bolOpenedWord = True
End If
wd.Visible = True ' Set this to true if you want to see the document open
On Error GoTo 0
Set doc = wd.Documents.Add("\\gsmstore2\COE\Testing Database\TFT1.docx")
DoCmd.OpenForm FormName:="FrmRelRecSenAll"
With doc
On Error Resume Next
'sends particular fields to corresponding FormFields in Word
.FormFields("PtName").Result = [Forms]![FrmAllTracker]![FrmSubTherapyRef].[Form].[Text62]
.FormFields("COENum").Result = Me.COEMR
.FormFields("RefRec").Result = Me.CaseOpen
.FormFields("FirstCont").Result = Me.CaseOpen
.FormFields("InitRecsRecv").Result = DLookup("FirstOfRecordsRec", "QryTrackerInitRecRecvCFFirst")
.FormFields("SuffRecs").Result = Me.SuffRecDate
.FormFields("Init2").Result = Me.InitCaseDate
.FormFields("TeamRev").Result = DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 14")
.FormFields("MCRMeet").Result = DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 6")
.FormFields("MCRMeetAct").Result = DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 6")
.FormFields("FTDate").Result = InputBox("Please enter Date of FT Release", "FT Release", Default)
.FormFields("FirstAppt").Result = InputBox("Please enter Date of 1st offered appt", "1st Offered Date", Default)
.FormFields("AssessDebrief").Result = DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 15")
.FormFields("RptSent").Result = DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 11")
.FormFields("FFollow").Result = DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 12")
.FormFields("LFollow").Result = DLookup("ContactDate", "QryTrackerLFollow")
.FormFields("CaseClosed").Result = Me.CaseClosed
If Not IsNull(DLookup("ContactDate", "QryTrackerTeamRev", "[ContactType] = 4")) Then
.FormFields("Bill").Result = "Yes"
Else
.FormFields("Bill").Result = "No"
End If
.Application.Activate
Set rng = ActiveDocument.Bookmarks("Releases").Range
rng.Text = concatData()
Set Tbl = rng.ConvertToTable
End With
'This foramats the table
With Tbl
.Columns(1).Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Columns(1).Borders(wdBorderBottom).LineWidth = wdLineWidth050pt
.Columns(1).Borders.InsideLineStyle = wdLineStyleSingle
.Columns(1).Borders.InsideLineWidth = wdLineWidth050pt
.Columns(1).Width = 125
.Columns(2).Width = 450
.Columns(3).Delete
End With
wd.ActiveDocument.SaveAs2 ("\\Filelocation\COE\Case Files\" & COEMR & "\Tracking Sheet" & " " & MDate & ".docx")
Set doc = Nothing
Set wd = Nothing
Set rg = Nothing
Set Tbl = Nothing
End Sub
I am trying to add a record to a record set through a form. one of the fields in the form is an attachment. How can i add the attachment into the record set as I keep receiving errors of "Data Type Mismatch"? I understand the attachment field is basically a record set with "FileData","FileName", "File Type" Fields, but how can i have vba add the attachment from the form I have to the record set??
below is the coding I use:
Private Sub Command31_Click()
Dim Db As Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Set Db = CurrentDb
Dim Message1, Message2, Title1, Default, MyValue1, MyValue2
Dim SN
Dim q As Long
Dim i As Long
Message1 = "ENTER TOTAL QUANTITY RECEIVED OF " & Me.Item ' Set prompt.
Title1 = "Total Quantity Received" ' Set title.
Default = "1" ' Set default.
' Display message, title, and default value.
MyValue1 = InputBox(Message1, Title1, Default)
i = 0
q = MyValue1
Do While (i < q)
Message2 = "ENTER S/N FOR ITEM NUMBER " & i + 1 ' Set prompt.
Title2 = "SERIAL NUMBER ENTRY" ' Set title.
Default = "1" ' Set default.
' Display message, title, and default value.
MyValue2 = InputBox(Message2, Title2, Default)
Set rs = Db.OpenRecordset("Inventory Transactions")
rs.Edit
rs.AddNew
Set rs2 = rs.Fields("Transaction Docs").Value
rs.Fields("Tx Date") = Date
rs.Fields("Project Code") = Me.Project_Code
rs.Fields("Transaction Type") = 1
rs.Fields("Transaction Item") = Me.Item
rs.Fields("Reference Document") = Me.Reference_Document
rs.Fields("Serial Number") = MyValue2
rs.Fields("Quantity") = 1
rs.Fields("Location") = Me.Location
rs.Fields("Entered by") = Me.Entered_by
rs.Fields("Recepient") = Me.Recepient
rs2.AddNew
rs2.Fields("FileData").LoadFromFile (Me.Transaction_Docs)
rs2.Update
'With rsatt1
'Do While Not rsatt1.EOF
'rsatt1.AddNew
'rsatt1.Fields("FileData") = rsatt1.Fields("FileData")
'rsatt1.Fields("FileName") = rsatt1.Fields("FileName")
'rsatt1.Fields("FileType") = rsatt1.Fields("FileType")
'rsatt1.Update
'.MoveNext
'Loop
'End With
'rsatt1.Close
Set rs2 = Nothing
rs.Update
rs.Close
i = i + 1
Loop
Set rs = Nothing
DoCmd.Close
DoCmd.OpenForm "MULTIPLE RECORDS GENERATOR"
DoCmd.Requery
Db.Close
End Sub
Need to find a way to offset the cell value in the email body. For whichever cell value triggers the email (meaning our target has been reached) I want to return the corresponding row value 12 columns to the left. You'll see in my code I've used Target.Offset(0, -12) but this is returning an error. I hope that makes sense.
Private Sub Worksheet_Calculate()
Dim Target As Range
With Me
Set Target = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp))
End With
If (Range("N45") = Range("F45")) Or (Range("N46") = Range("F46")) Or (Range("N47") = Range("F47")) Or (Range("N48") = Range("F48")) Or (Range("N50") = Range("F50")) Or (Range("N51") = Range("F51")) Or (Range("N52") = Range("F53")) Or (Range("N55") = Range("F55")) Or (Range("N56") = Range("F56")) Or (Range("N57") = Range("F57")) Or (Range("N58") = Range("F58")) Or (Range("N59") = Range("F59")) Or (Range("N61") = Range("F61")) Or (Range("N62") = Range("F62")) Or (Range("N63") = Range("F63")) Or (Range("N65") = Range("F65")) Or (Range("N66") = Range("F66")) Or (Range("N67") = Range("F67")) Or (Range("N68") = Range("F68")) Or (Range("N70") = Range("F70")) Or (Range("N71") = Range("F71")) Or (Range("N73") = Range("F73")) Or (Range("N74") = Range("F74")) Or (Range("N75") = Range("F75")) Or (Range("N76") = Range("F76")) Or (Range("N77") = Range("F77")) Or (Range("N79") = Range("F79")) Or (Range("N80") = Range("F80")) Or (Range("N81") = Range("F81")) Or (Range("N83") = Range("F83")) And _
(Range("N84") = Range("F84")) Or (Range("N85") = Range("F85")) Or (Range("N87") = Range("F87")) Or (Range("N88") = Range("F88")) Or (Range("N89") = Range("F89")) Or (Range("N91") = Range("F91")) Or (Range("N92") = Range("F92")) Or (Range("N93") = Range("F93")) Or (Range("N95") = Range("F95")) Or (Range("N96") = Range("F96")) Or (Range("N97") = Range("F97")) Or (Range("N99") = Range("F99")) Or (Range("N100") = Range("F100")) Or (Range("N101") = Range("F101")) Or (Range("N103") = Range("F103")) Or (Range("N104") = Range("F104")) Or (Range("N105") = Range("F105")) Or (Range("N106") = Range("F106")) Or (Range("N108") = Range("F108")) Or (Range("N109") = Range("F109")) Or (Range("N110") = Range("F110")) Or (Range("N111") = Range("F111")) Or (Range("N113") = Range("F113")) Or (Range("N114") = Range("F114")) Or (Range("N115") = Range("F115")) Or (Range("N116") = Range("F116")) Or (Range("N117") = Range("F117")) Or (Range("N118") = Range("F118")) Or (Range("N121") = Range("F121")) And _
(Range("N122") = Range("F122")) Or (Range("N123") = Range("F123")) Or (Range("N124") = Range("F124")) Or (Range("N125") = Range("F125")) Or (Range("N127") = Range("F127")) Or (Range("N128") = Range("F128")) Or (Range("N132") = Range("F132")) Or (Range("F134") = Range("N134")) Or (Range("N136") = Range("F136")) Or (Range("N138") = Range("F138")) Or (Range("N140") = Range("F140")) Or (Range("N142") = Range("F142")) And _
(Range("N145") = Range("F145")) Or (Range("N146") = Range("F146")) Or (Range("N147") = Range("F147")) Or (Range("N148") = Range("F148")) Or (Range("N149") = Range("F149")) Or (Range("N150") = Range("F150")) Or (Range("N153") = Range("F153")) Or (Range("N154") = Range("F154")) Or (Range("N156") = Range("F156")) Or (Range("N157") = Range("F157")) Or (Range("N159") = Range("F159")) Or (Range("N160") = Range("F160")) Or (Range("N161") = Range("F161")) Or (Range("N162") = Range("F162")) Or (Range("N163") = Range("F163")) Or (Range("N164") = Range("F164")) Or (Range("N166") = Range("F166")) Or (Range("N167") = Range("F167")) Or (Range("N168") = Range("F168")) Or (Range("N169") = Range("F169")) Or (Range("N170") = Range("F170")) Or (Range("N171") = Range("F171")) Or (Range("N173") = Range("F173")) Or (Range("N174") = Range("F174")) Or (Range("N175") = Range("F175")) Or (Range("N176") = Range("F176")) Or (Range("N177") = Range("F177")) Or (Range("N178") = Range("F178")) And _
(Range("N180") = Range("F180")) Or (Range("N182") = Range("F182")) Or (Range("N184") = Range("F184")) Or (Range("N185") = Range("F185")) Or (Range("N186") = Range("F186")) Or (Range("N187") = Range("F187")) Or (Range("N188") = Range("F188")) Or (Range("N189") = Range("F189")) Or (Range("N191") = Range("F191")) Or (Range("N192") = Range("F192")) Or (Range("N193") = Range("F193")) Or (Range("N195") = Range("F195")) Or (Range("N196") = Range("F196")) Or (Range("N197") = Range("F197")) Or (Range("N198") = Range("F198")) Or (Range("N199") = Range("F199")) Or (Range("N200") = Range("F200")) Or (Range("N201") = Range("F201")) Or (Range("N202") = Range("F202")) Or (Range("N203") = Range("F203")) Or (Range("N205") = Range("F205")) Or (Range("N206") = Range("F206")) Or (Range("N207") = Range("F207")) Or (Range("N208") = Range("F208")) Or (Range("N209") = Range("F209")) Or (Range("N210") = Range("F210")) Or (Range("N211") = Range("F211")) Or (Range("N212") = Range("F212")) And _
(Range("N213") = Range("F213")) Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
Target.Offset(0, -12) & " has reached its target"
On Error Resume Next
With xOutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "Target Reached"
.Body = xMailBody
.Send 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Here I have used the Worksheet_Change event and the Offset works fine.
Dim xRg As Range
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Target, Range("D1:D99"))
If xRg Is Nothing Then Exit Sub
If (Range("D7") > Range("E7")) Or (Range("D8") > Range("E8")) Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
xRg.Offset(0, -3) & " has reached its target"
On Error Resume Next
With xOutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "Target Reached"
.Body = xMailBody
.Send 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Target.Offset(0, -12) in your Mail_small_Text_Outlook isn't defined. You can't set a variable in one subroutine and then use it in another unless that variable has been defined globally (outside of all subroutines and functions) or it is passed as a parameter to the subroutine.
Try instead:
Sub Mail_small_Text_Outlook(Target as Range)
Then calling that subroutine like:
Call Mail_small_Text_Outlook(Target)
With that you are passing the variable Target to the Mail_small_Text_Outlook subroutine.
Alternatively to set Target as a global variable so it is available to subroutines and functions in your VBAProject (I wouldn't in this case for reasons). You add to the top of your code (above your worksheet_calculate routine):
Public Target as Range
Then remove your declaration of Target in your worksheet_calculate routine:
'Dim Target As Range
Although, if you do this, then change the name of the variable since there are other built in subroutines like Worksheet_Change() that have Target as a built in variable and the scope is going to get all weird then.
I am trying to do a query of a linked table. After I get the results, I need to do 1 of 2 things. Either say it passed or failed. Here is the code I have written. It doesn't give me any errors, nor does it run correctly. When I input a SN I know doesn't have any entries it doesn't run the second part (the fail part).
Private Sub SQL_Check()
Dim rs As DAO.Recordset
Dim sqlMax As String
Dim result As String
sqlMax = "Select count(1) FROM dbo_Event WHERE [AssemblyNo] = 'SYSCHATESTE' and [SerialNo] = '" & Me.txtUnitNo & "' and [ProcessTyp] = 'SF1';"
Set rs = CurrentDb.OpenRecordset(sqlMax)
If rs.Fields.Count = 1 Then
txtECCT.BackColor = vbGreen
txtECCT.ForeColor = vbBlack
txtECCT.Value = "Passed"
GoTo la
End If
If rs.Fields.Count = 0 Then
Set rs = Nothing
Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from tblScannedParts")
rec.AddNew
rec("Inspector") = Me.txtUserId
rec("PO Number") = Me.txtWorkOrderNo
rec("Assembly") = Me.txtAssem
rec("SERIAL Number") = Me.txtUnitNo
rec("DateScanned") = CStr(Now())
rec("Result") = "Failed"
rec("Defect Type") = "Missing ECCT"
rec("Comments") = strFileContent
rec("Qty") = "1"
rec.Update
txtStatus.BackColor = vbRed
txtStatus.ForeColor = vbBlack
txtStatus.Value = "Failed"
MsgBox "Please take unit to NCM Cart for review.", vbCritical, "Unit Not Ready for DOF QA"
txtAssem.SetFocus
End If
la:
Set rs = Nothing
End Sub
The issue is that the recordset rs is based on a SELECT which returns one field, so your If condition, rs.Fields.Count = 1, will always be True.
Conversely, the code within the If rs.Fields.Count = 0 Then block could never run because Fields.Count would never be zero. And actually, Access does not even evaluate that condition because you included GoTo la in the previous If block ... which quickly exits the procedure. Be wary of GoTo
If you want to base the action on a count of matching records, I think the logic should be simpler with DCount().
Dim strCriteria As String
Dim lngMatchCount As Long
strCriteria = "[AssemblyNo] = 'SYSCHATESTE' AND [SerialNo] = '" & Me!txtUnitNo.Value & "' AND [ProcessTyp] = 'SF1'"
Debug.Print strCriteria '<- inspect this in Immediate window; Ctrl+g will take you there
lngMatchCount = DCount("*", "dbo_Event", strCriteria)
If lngMatchCount > 0 Then
' do the 'Passed' thing
Else
' do the 'Failed' thing
End If
I am new to VBA and am severely stuck! I have 12 cells that I need to add specific text to, but only if the cells are blank. I managed to find code for 1 of them which is shown below:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$D$3" Then
If Target.Value = "Insert name of project (if known)" Then
Target.Font.ColorIndex = xlAutomatic
Target.Value = ""
Exit Sub
End If
End If
If [D3].Value = "" Then
[D3].Value = "Insert name of project (if known)"
[D3].Font.ColorIndex = 1
Else
[D3].Font.ColorIndex = xlAutomatic
End If
End Sub
However, seemingly I can only use this once per sheet. I need code that is similar to this that will hopefully do the same job. The remaining 11 cells need to have unique text.
Basically what I am trying to do is prompt the user to insert details in each of these cells and once the cells are filled, the form will be complete.
Any assistance is appreciated.
Hi, Apologies for the delay. This is the final edit, which works perfectly. I thought I was going to have an issue with 'undo' (CTRL+Z) but it seems to be fine now. Thanks again.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim clls(1 To 12) As String
Dim msg(1 To 12) As String
Dim i As Long, addr As String, c As Range
clls(1) = "D3": msg(1) = "Insert name of project (if known)"
clls(2) = "D4": msg(2) = "Insert closest street address"
clls(3) = "H3": msg(3) = "Insert name of landowner (if applicable)"
clls(4) = "H4": msg(4) = "Insert name of Developer (if applicable)"
clls(5) = "H6": msg(5) = "Insert name of PM Co. (if different from above)"
clls(6) = "H7": msg(6) = "Insert name of Designer (if applicable)"
clls(7) = "H8": msg(7) = "Insert name of Constructor"
clls(8) = "L3": msg(8) = "Insert project number (if known)"
clls(9) = "L6": msg(9) = "Insert name"
clls(10) = "L7": msg(10) = "Insert submission date"
clls(11) = "D10": msg(11) = "Brief description of project: Adjustment, deviation, main upsizing, main extension, lead-in, lead-out, etc."
clls(12) = "D11": msg(12) = "Insert length of asset (number only)"
Set c = Target.Cells(1)
addr = c.Address(False, False)
For i = 1 To UBound(clls)
If addr = clls(i) Then
If c.Value = msg(i) Then
c.Font.ColorIndex = xlAutomatic
c.Value = ""
End If
Else
With Me.Range(clls(i))
If .Value = "" Then
.Value = msg(i)
.Font.ColorIndex = 1
End If
End With
End If
Next i
End Sub
Might need a bit of tweaking...
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim clls(1 To 5) As String
Dim msg(1 To 5) As String
Dim i As Long, addr As String, c As Range
clls(1) = "D3": msg(1) = "Message 1"
clls(2) = "D4": msg(2) = "Message 2"
clls(3) = "D5": msg(3) = "Message 3"
clls(4) = "D6": msg(4) = "Message 4"
clls(5) = "D7": msg(5) = "Message 5"
Set c = Target.cells(1)
addr = c.Address(False, False)
For i = 1 To UBound(clls)
If addr = clls(i) Then
If c.Value = msg(i) Then
c.Font.ColorIndex = xlAutomatic
c.Value = ""
End If
Else
With Me.Range(clls(i))
If .Value = "" Then
.Value = msg(i)
.Font.ColorIndex = 1
End If
End With
End If
Next i
End Sub