Help with formatting String (1 Viewer)

Tupacmoche

Registered User.
Local time
Today, 07:21
Joined
Apr 28, 2008
Messages
291
I have code to dynamically assign a string to a Combo Box's Row Source. If, I type it into the Row Source property Sheet it works fine:



"Soft";"Joint";"IHO";"IMO";"Faculty & Friends"


But here is the vba:


Dim strPerson As String
Dim strOrg As String

strPerson = ""Soft";"Joint";"IHO";"IMO";"Faculty & Friends""
strOrg = ""Soft";"IHO";"IMO";"Faculty & Friends""

If Nz(DLookup("PersonorOrgan", "dbo_tblTransmittalInfo", "GiftID= " & [GiftID] & " "), "P") = "P" Then
Me.SoftGiftType.Value = strPerson
Else
Me.SoftGiftType.Value = strOrg
End If


The assignment of the two strings strPerson, and strOrg gives me an syntax error msg. How can, I fix the string and make this work?:mad:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:21
Joined
Oct 29, 2018
Messages
21,477
Hi. How about using a single quote instead?


Code:
strPerson = "'Soft';'Joint';'IHO';'IMO';'Faculty & Friends'"
strOrg = "'Soft';'IHO';'IMO';'Faculty & Friends'"
 

Tupacmoche

Registered User.
Local time
Today, 07:21
Joined
Apr 28, 2008
Messages
291
Thanks! theDBguy it's been a long day.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:21
Joined
Oct 29, 2018
Messages
21,477
Hi. You're welcome. Have a good weekend!
 

Tupacmoche

Registered User.
Local time
Today, 07:21
Joined
Apr 28, 2008
Messages
291
New problem follow-up. This string is being assigned to a combo box row source. When entered using the GUI this string works fine:


"Soft";"Joint";"IHO";"IMO";"Faculty & Friends" That is with the double quotes but when I change to single quotes:


"'Soft';'Joint';'IHO';'IMO';'Faculty & Friends'" Instead of getting a drop down with items to choose from a get one long string:


"'Soft';'Joint';'IHO';'IMO';'Faculty & Friends'" How can this be fixed?:confused:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:21
Joined
Oct 29, 2018
Messages
21,477
Ah, how about let's try not using any quotes at all? For example:

strPerson = "Soft;Joint;IHO;IMO;Faculty & Friends"
Me.cboName.RowSource = strPerson
Me.cboName.RowSourceType = "Value List"
 

Tupacmoche

Registered User.
Local time
Today, 07:21
Joined
Apr 28, 2008
Messages
291
Here is all the code. Now, the combo box is not being populated.


Private Sub SoftGiftType_AfterUpdate()
Dim strPerson As String
Dim strOrg As String

strPerson = "Soft;Joint;IHO;IMO;Faculty & Friends"
strOrg = "Soft;IHO;IMO;Faculty & Friends"

If Nz(DLookup("PersonorOrgan", "dbo_tblTransmittalInfo", "GiftID= " & [GiftID] & " "), "P") = "P" Then
Me.SoftGiftType.RowSource = strPerson
Me.SoftGiftType.RowSourceType = "Value List"
Else
Me.SoftGiftType.RowSource = strOrg
Me.SoftGiftType.RowSourceType = "Value List"
End If
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:21
Joined
Oct 29, 2018
Messages
21,477
Hi. I just tried it and it worked for me. Can you post a sample copy of your database with test data?
 

Tupacmoche

Registered User.
Local time
Today, 07:21
Joined
Apr 28, 2008
Messages
291
Should this be in the on load or after update event?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:21
Joined
Oct 29, 2018
Messages
21,477
Should this be in the on load or after update event?
Hi. It all depends on when you want it to happen. In my quick test, I just used a button's Click event. What exactly are you trying to do? If you're trying to modify the Row Source of a combo based on the current record, then maybe you want to use the Form's Current event.
 

Tupacmoche

Registered User.
Local time
Today, 07:21
Joined
Apr 28, 2008
Messages
291
I put it into the after update event. But when, I researched it further everyone said to put it into the On load event. In any event it's now working thanks again!:)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:21
Joined
Oct 29, 2018
Messages
21,477
Okay. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom