Sarah-
John,
Sorry about not including the complete thread. I hope I got it this time. Anyhow I am still getting the error: 'run-time error 13, type mismatch' . I can confirm that strName is "Format" , dbText is 10 and strSetting is "Short Time". I did not capitalize in my previous email.
This is my code (I copy pasted your code, but it is not working):
Sub SetFieldProperty(fldTemp As DAO.Field, strName As String, strSetting As String)
Dim prpNew As Property
Dim errLoop As Error' Attempt to set the specified property.
On Error GoTo Err_Property
fldTemp.Properties(strName) = strSetting
On Error GoTo 0Exit Sub
Err_Property:
' Error 3270 means that the property was not found.
If DBEngine.Errors(0).Number = 3270 Then
' Create property, set its value, and append it to the
' Properties collection.
Set prpNew = fldTemp.CreateProperty(strName, dbText, strSetting)
dbsTemp.Properties.Append prpNew
Resume Next
Else
'If different error has occurred, display message.
For Each errLoop In DBEngine.Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.Description
Next errLoop
End
End IfEnd Sub
Any help you can extend me is greatly appreciated.Thanks
Sarah
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote:Sarah-Well, for starters you didn't include the original thread in your reply, so I had to go hunt it down on the web.dbText should be 10, not "10".The property name is Format, not format. And the value should be Short Time, not short time. Other than that, I can't see what might be wrong.John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)Sarah-On Feb 12, 2014, at 6:20 PM, <sarahk@...> <sarahk@...> wrote:John,
I tried your code, but I get error 'run-time error 13, type mismatch' on this statement:
Set prpNew = fldTemp.CreateProperty(strName, dbText, strSetting)strName ="format"
dbText="10"
strsetting="short time"
What am I doing wrong?
Sarah
You cannot do it with SQL because the Format property is what you need to set, and that's not defined in SQL.First, you need a little routine to create a new field string property:Sub SetFieldProperty(fldTemp As DAO.Field, strName As String, _ strSetting As String) Dim prpNew As Property Dim errLoop As Error ' Attempt to set the specified property. On Error GoTo Err_Property fld.Properties(strName) = strSetting On Error GoTo 0 Exit Sub Err_Property: ' Error 3270 means that the property was not found. If DBEngine.Errors(0).Number = 3270 Then ' Create property, set its value, and append it to the ' Properties collection. Set prpNew = fldTemp.CreateProperty(strName, _ dbText, strSetting) dbsTemp.Properties.Append prpNew Resume Next Else ' If different error has occurred, display message. For Each errLoop In DBEngine.Errors MsgBox "Error number: " & errLoop.Number & vbCr & _ errLoop.Description Next errLoop End End If End SubChange your code like this:Dim db As DAO.Database, tdf As DAO.TableDef, fld As DAO.Field' Point to this databaseSet db = CurrentDB' Create the new table using SQLdb.Execute "CREATE TABLE testss3(ID COUNTER PRIMARY KEY, " & _"[stu id] LONG, " & _
"description TEXT(50), " & _
"document TEXT(255), " & _
"timexx DATETIME, " & _
"documentdate DATETIME ," & _
"entrydate DATETIME)", dbFailOnError' Make sure this copy of the database knows about the new tabledb.TableDefs.Refresh' Get the new tableSet tdf = db.Tabledefs("testss3")' Get the first fieldSet fld = tdf.Fields("timexx")' Call the Set Property codeSetFieldProperty fld, "Format", "Short Time"' Get the second fieldSet fld = tdf.Fields("documentdate")' Set its Format propertySetFieldProperty fld, "Format", "Short Date"' Clean upSet fld = NothingSet tdf = NothingSet db = NothingJohn Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
| Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (6) |
Tidak ada komentar:
Posting Komentar